English 中文(简体)
姓名空间问题。
原标题:Namespace problem .net
  • 时间:2011-03-02 20:06:13
  •  标签:
  • asp.net

我在我的蚊帐应用中设立了一个称为“Controls”的夹。 其中有用户控制(例如:RangePicker.ascx)。 现在,我正在我的手法中设置一个班子,我正试图向一位名叫RangePicker的人做一些事情。

 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?)

我如何适当地将这一用户控制归入一个类别?

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;
        }
    ........

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;
            }
        }
最佳回答

随着网站项目的不断发展。 网站上的项目没有名称空间概念,对参考资料的管制可能会有问题。 通过关于第一个环节的一些意见:

http://forums.asp.net/p/1035070/1428363.aspx

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

在应用中控制用户。 更有甚者,使用网络应用项目,你应当能够避免这一问题。

<>>>>>

在网站项目中获取用户控制问题的一个途径是制定该守则,然后将用户控制放在应用程序的夹中:

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

个人而言,这只是一个微薄的黑板,微软不建议:

http://msdn.microsoft.com/en-us/library/t990ks23.aspx

我将把它作为海关服务器的控制权,并把它放在应用程序中。 这应当解决提及问题。 归根结底,网站项目并不是要认真工作,这只是原因之一。 你的最佳选择是把这个项目建设成一个网络应用项目——我可以想到选择网站模板的任何合理理由(对比优化也可以与《世界行动计划》保持一致)。

问题回答

“DateRangePicker.ascx.cs”是否实施“CambitCMS.Controls.DateRangePicker”类或“CambitCMS.DateRangePicker”类? 确保命名是正确的。


“Controls_DateRangePicker”与“CambitCMS.Controls.DateRangePicker”并不相同,这就是为什么汇编者报告错误。 在这两种档案中都使用同一类别的名称,而且应当加以罚款,但现在看来是这样。


如果网站是作为网络应用程序建立的,则可能必须加以汇编,以便英特尔利斯特尔公司能够选择哪类名称,如果你在C#代码中改动的话,那么在你本人有其他错误的情况下,可能必须更新目录。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签