使用asp.net使div / htmlgeneric控件可见

时间:2012-06-27 07:16:53

标签: c# asp.net

我有一个像这样的div的用户控件:

 <div runat="server" id="pnlShippingMethods" class="checkoutstep">
                            <div class="steptitle">
                                <%=GetLocaleResourceString("CheckoutOnePage.ShippingMethods.Title")%>
                                <div style="float: right;">                                  
                                </div>
                                Date from checkout page one for ship method update panel is <%= DateTime.Now.ToString() %>
                            </div>
                            <asp:Panel runat="server" ID="pnlShippingMethodsContent" class="stepcontent">
                                <nopCommerce:CheckoutShippingMethod ID="ctrlCheckoutShippingMethod" runat="server"
                                    OnePageCheckout="true" />
                            </asp:Panel>
                        </div>

我在放置此控件的页面加载时使用visible = false。然后从同一页面上的另一个控件我试图让它看起来像这样:

HtmlGenericControl pnlShippingMethods = this.Parent.Parent.Parent.Parent.Parent.FindControl("pnlShippingMethods") as HtmlGenericControl;              

        pnlShippingMethods.Visible = true;

我可以从其他用户控件而不是div中创建可见/不可见的用户控件CheckoutShippingMethod。请建议如何使其可见

1 个答案:

答案 0 :(得分:3)

您可以使用公共方法代替它。

1)在要显示/隐藏的自定义控件中创建公共方法/属性     面板。

public void ShowPanel(bool isVisible)
{
   this.pnlShippingMethods.Visible = isVisible;
}

2)从另一个控件中调用它来显示隐藏面板。

yourCustomrControlObject.ShowPanel(true);