【问题标题】:Prevent loading of ContentPlaceHolder from MasterPage防止从 MasterPage 加载 ContentPlaceHolder
【发布时间】:2017-04-12 04:01:56
【问题描述】:

我有一个母版页、contentplaceholder 和一个 .ascx 页面。 用户在 Masterpage 中输入他的用户名-密码。

如果用户输入错误的用户名和密码组合,我想防止内容占位符的加载。目前我只是禁用它的可见性,这可以解决问题,但页面仍在加载,进入数据库等,这是无用的,因为它们都不会显示。

【问题讨论】:

    标签: c# asp.net webforms master-pages contentplaceholder


    【解决方案1】:

    您可以加载控件dynamically

    private WebUserControl1 userControl;
    
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (loginOK == true)
        {
            buildControls();
        }
    }
    
    private void buildControls()
    {
        userControl = (WebUserControl1)LoadControl("~/WebUserControl1.ascx");
        PlaceHolder1.Controls.Add(userControl);
    }
    

    需要在每个 Page_load 上重新创建动态添加的控件 (包括回发)。所以当用户 已登录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-24
      • 1970-01-01
      相关资源
      最近更新 更多