【发布时间】:2011-03-17 22:43:37
【问题描述】:
我的问题与此线程有些相关:How to avoid Initialization of web user control inside aspx?
用户控件应该仅在单击按钮时可见。 所以我的用户控件是这样设置的:
<example:usercontrol ID="idControl" runat="server" Visible="false" />
<asp:Button ID="showMyControl" runat="server" OnClick="ShowMyControl" /
并且用户控件本身会检查他是否可见:
protected void Page_Load( object sender, EventArgs e ) {
// only execute if the user control is visible
if ( this.Visible ) {
...
}
}
当我单击按钮时,我将 usercontrol 的属性 Visible 设置为 true,但是当回发发生时,usercontrol 的 Page_Load 中的 Visible-property 仍设置为 false。
我的 UserControl 可能会先加载,然后再设置 Visible-property? 有没有简单的方法来解决这个问题?
提前致谢!
【问题讨论】: