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



我有一个带有如下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>

我在放置此控件的页面加载中使可见 = false 。然后从同一页面上的另一个控件,我试图使其可见,如下所示:

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

我能够从其他用户控件而不是div 制作可见/不可见的用户控件 CheckoutShippingMethod 。请建议如何使其可见

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

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

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

2)从另一个控件调用此控件以显示隐藏面板。

yourCustomrControlObject.ShowPanel(true);

最新更新