命名空间的问题.NET

编程入门 行业动态 更新时间:2024-10-24 06:31:51
本文介绍了命名空间的问题.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在我的asp应用程序创建了一个名为控件文件夹中。在该文件夹是用户控件(1为DateRangePicker.ascx例如)。现在我创造我的应用程序code文件夹中的一类,我试图投的​​东西到DateRangePicker,

DateRangePicker DRP =(CambitCMS.Controls.DateRangePicker)gvListing.Parent.Parent.FindControl(ucDateRangePicker);

和我收到以下错误:错误2类型或命名空间名称'控制'在命名空间'CambitCMS(是否缺少程序集引用?)不存在

我如何正确地在一个类中引用这个用户的控制?

我要我的ListingsBasePage级引用我DateRangePicker用户控件,但如果我把一个命名空间围绕整个用户控件code它打破了用户的控制,它说都喜欢的文本框,标签等方面的事情不存在于目前的情况下,当一个命名空间是围绕code包裹。

下面是类ListingsBasePage我在哪里triyng引用该用户控件的开始

使用系统;使用System.Data这;使用System.Configuration;使用System.Linq的;使用的System.Web;使用System.Web.Security;使用System.Web.UI程序;使用System.Web.UI.HtmlControls;使用System.Web.UI.WebControls;使用System.Web.UI.WebControls.WebParts;使用System.Xml.Linq的;公共部分类ListingsBasePage:System.Web.UI.Page{    保护无效gvListing_On preRender(对象发件人,EventArgs的发送)    {        保护无效gvListing_On preRender(对象发件人,EventArgs的发送)        {            GridView控件gvListing =(GridView的)发件人;            DateRangePicker DRP =(CambitCMS.Controls.DateRangePicker)gvListing.Parent.Parent.FindControl(ucDateRangePicker);            gvListing.PageSize = drp.recordsPerPage;        }    ........

而DatRangePickerControl开始

使用系统;使用System.Web.UI.HtmlControls;使用System.Web.UI程序;使用System.Web.UI.WebControls;    公共部分类Controls_DateRangePicker:System.Web.UI.UserControl    {        公共字符串寄件者        {            得到            {                返回tbFromDate.Text;            }        }

解决方案

这一次出现的时间和时间与网站的项目。有没有在网站上的项目名称空间的概念,并引用控件可以是有问题的。

:通过一些第一个链接的评论去

west-wind/weblog/posts/3016.aspx

forums.asp/p/1035070/1428363.aspx

的www.$c$crsbarn/post/2008/06/ASPNET-Web-Site-versus-Web-Application-Project.aspx(披露,这最后一个环节是我自己的博客)

尝试把在APP_ code文件夹的用户控制。更妙的是,使用Web应用程序项目,而不是和你应该能够避免这个问题。

更新

在周围项目的网站访问用户控制问题的方法之一是内联code然后把用户控制在APP_ $ C $文件夹C:

odeto$c$c/blogs/scott/archive/2005/10/01/asp-net-2-0-user-controls-in-app_$c$c.aspx

个人而言,这是一个草率的黑客在最好的,微软不建议:

msdn.microsoft/en-us/library/ t990ks23.aspx

我想创建它作为一个(的.cs)的自定义服务器控件,并放进了APP_ code文件夹中。这应该解决的问题引用。最终,网站项目不适合严肃的工作,这只是原因之一。最好的选择是建立这个作为一个Web应用程序项目 - 我想不出任何合乎逻辑的理由选择了网站模板(编译优化也可以用WAP GOT)

I have created a folder called "Controls" in my asp application. In that folder are user controls (1 being DateRangePicker.ascx for example). Now I am creating a class in my app code folder and I am trying to cast something to a DateRangePicker,

DateRangePicker drp = (CambitCMS.Controls.DateRangePicker)gvListing.Parent.Parent.FindControl("ucDateRangePicker");

And I am getting the following error: Error 2 The type or namespace name 'Controls' does not exist in the namespace 'CambitCMS' (are you missing an assembly reference?)

How do I properly reference this user control in a class?

I want my "ListingsBasePage" class to reference my DateRangePicker usercontrol, but if I put a namespace around the whole user control code it breaks the user control, it says all the things like the textboxes, labels, etc dont exist in current context when a namespace is wrapped around the code.

Here is the start of the class "ListingsBasePage" where I am triyng to reference the usercontrol

using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class ListingsBasePage : System.Web.UI.Page { protected void gvListing_OnPreRender(object sender, EventArgs e) { protected void gvListing_OnPreRender(object sender, EventArgs e) { GridView gvListing = (GridView)sender; DateRangePicker drp = (CambitCMS.Controls.DateRangePicker)gvListing.Parent.Parent.FindControl("ucDateRangePicker"); gvListing.PageSize = drp.recordsPerPage; } ........

And the start of the DatRangePickerControl

using System; using System.Web.UI.HtmlControls; using System.Web.UI; using System.Web.UI.WebControls; public partial class Controls_DateRangePicker : System.Web.UI.UserControl { public String FromDate { get { return tbFromDate.Text; } }

解决方案

This comes up time and time again with website projects. There is no concept of namespaces in website projects and referencing controls can be problematic. Go through some of the comments on the first link:

west-wind/weblog/posts/3016.aspx

forums.asp/p/1035070/1428363.aspx

www.codersbarn/post/2008/06/ASPNET-Web-Site-versus-Web-Application-Project.aspx (disclosure, this last link is my own blog)

Try putting the user control in the App_Code folder. Better still, use a Web Application Project instead and you should be able to avoid this issue.

UPDATE

One way around the problem of accessing user controls in website projects is to inline the code then put the user control in the App_Code folder:

odetocode/blogs/scott/archive/2005/10/01/asp-net-2-0-user-controls-in-app_code.aspx

Personally, this is a sloppy hack at best, and Microsoft do not recommend it:

msdn.microsoft/en-us/library/t990ks23.aspx

I would create it as a custom server control with a (.cs) and put that in the App_Code folder. This should solve the referencing issue. Ultimately, website projects are not intended for serious work and this is just one reason why. Your best option is to build this as a Web Application project - I can't think of any logical reason for opting for the website template (compile optimizations can also be got with the WAP).

更多推荐

命名空间的问题.NET

本文发布于:2023-11-09 06:03:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571579.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:空间   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!