English 中文(简体)
所有控制在用户控制范围内都是无效的。
原标题:All controls are null within usercontrol

我有一个用户配置,除其他控制外,使用用户配置。

在<代码>ascx中,第一卷有以下代码:

<%@ Register TagPrefix="tag" Namespace="some.name.space" Assembly="some.assembly" %>
<tag:control ID="test" runat="server" />

在我的<代码>Page_Load方法中,我试图像样在试验中设定一个财产:

test.Text = "Hello World!";

这实际上把字面控制的案文财产定在我的用户控制下test

这是一种例外:

不针对物体的事例提出反对

试图确定

lblTest.Text = value; 

页: 1

我没有正确地增加用户控制? 在登记塔格人时,我是否应该——或者我是否必须——具体说明<代码>Src的财产? 如果是的话,我必须登记我使用的每一用户控制?

This also results in no controls loading in usercontrol and all controls are null within usercontrol.

最佳回答

如果用户控制在你目前的项目中,那么你需要将电弧列入登记表:

<%@ Register TagPrefix="uc1" TagName="NavTop" Src="controls/NavTop.ascx" %>

然而,如果你在不止一页使用这一用户控制,那么你也可以在网上登记。 召集:

<system.web>
  <pages>
    <controls>
      <add tagPrefix="uc1" tagName="NavTop" src="~/controls/NavTop.ascx" />
    </controls>
  </pages>
</system.web>

了解的另一个情况是,有时视力演播室设计师没有“见”你对网页的控制所作的改动,如果你只是对源头的看法作出改动。 例如,如果你改用控制名称,你可以最终以星号的新名称进行控制,但在设计人档案中用旧名称进行控制。 在经营时,这将导致设计商的财产无效。

在多次被烧毁后,如果我对来源观点作任何改动,我要么检查设计人档案是否得到正确更新,要么我转向设计观点,作小改动,然后节省页/用户的控制。

问题回答

当我以错误的方式在守则中增加用户控制时,我就存在这一问题。 页: 1 选择控制权的洛德·科蒂尔方法只能使用新的方法。

        //WRONG
        UserControls.BingoCardPage bcp = new UserControls.BingoCardPage();
        form1.Controls.Add(bcp);
        //RIGHT
        UserControls.BingoCardPage bcp = (UserControls.BingoCardPage)Page.LoadControl("~/UserControls/BingoCardPage.ascx");
        form1.Controls.Add(bcp);

这里的问题通常是由于用户控制的工作量机械化,因此通常在网页后装上。 因此,在含有网页上载方法的期间,尚未开始对您的用户控制(造成负重)实行控制。 围绕这一点开展工作的一个途径是,在用户控制上建立和设定财产,并在“国际不动产”网页上安装用户控制线/播种其自己的国际不动产。 替代方法。

Something like this:

//Page
protected void Page_Load(object sender, EventArgs e)
{
    test.Text = "Hello World!";
}

//User Control
public string Text {get; set;}

protected void Page_Load(object sender, EventArgs e)
{
    lblTest.Text = Text;
}

Please try to put code in Page_prerender event of page. It will work for you.





相关问题
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!

热门标签