[英]Access control of dynamically added user control from parent page
I have a Product.aspx page in which i have a asp:panel
. 我有一个Product.aspx页面,其中有一个
asp:panel
。 I am adding a UserControl
in it dynamically using: 我使用以下方法在其中动态添加一个
UserControl
:
protected void Page_Load(object sender, EventArgs e)
{
UserControl userControl = (UserControl)this.LoadControl(Programs/Test/Test.ascx);
this.pnlLayoutDetails.Controls.Add(userControl);
LayoutPanels = pnlLayoutDetails.Controls[1];
}
I have a button in Product.aspx page. 我在Product.aspx页面中有一个按钮。 I am hiding some
Panel
s from UserControl
onClick
of this button. 我从此按钮的
UserControl
onClick
隐藏了一些Panel
。 Code is executing properly but when i see output it shows no effect (all controls are visible). 代码正确执行,但是当我看到输出时,它没有任何效果(所有控件都是可见的)。
code for button_click
button_click
代码
var pnlLayout = (Panel)LayoutPanels.FindControl("pnlLayout" + layout.LayoutID.ToString());
if (pnlLayout != null)
pnlLayout.Visible = false;
UPDATE: If i remove ajax panel from aspx page then it works fine. 更新:如果我从aspx页面删除ajax面板,那么它工作正常。 But with ajax panel it creates problem.
但是使用ajax面板会产生问题。 I am not able to figure it out.
我无法弄清楚。 Please suggest.
请提出建议。
Thanks 谢谢
I guess it is because you might not have panel in update panel section
. 我猜这是
because you might not have panel in update panel section
。
try moving you panel to aspx page. 尝试将面板移至aspx页面。 it will solve your problem.
它会解决您的问题。
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel runat="server" ID="pnlLayoutDetails" >
//dynamically added usercontrol
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
then execute this it will work. 然后执行此操作即可。
var pnlLayout = (Panel)LayoutPanels.FindControl("pnlLayout" + layout.LayoutID.ToString());
if (pnlLayout != null)
pnlLayout.Visible = false;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.