开发者

Programmatically Cancel Control Initialisation

开发者 https://www.devze.com 2022-12-16 04:01 出处:网络
Su开发者_开发问答ppose I have a user control MyControl.ascx, and I put it in the Default.aspx like this:

Su开发者_开发问答ppose I have a user control MyControl.ascx, and I put it in the Default.aspx like this:

<uc1:MyControl id="MyControl" runat="server">

Now in the code-behind of Default.aspx I do this:

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    MyControl.Visible = false;
}

The problem is that even I do not render MyControl, it is still being initialised and goes through the entire ASCX life cycle (OnLoad, etc). Is there a way to prevent the control from being initialised at all?

Thanks.


Instead of adding it to aspx better add it to a Placeholder from code behind dynamically. This would allow you to initialise it when you require.

Happy coding.

0

精彩评论

暂无评论...
验证码 换一张
取 消