简体   繁体   中英

Prevent loading of ContentPlaceHolder from MasterPage

I have a masterpage, contentplaceholder and an .ascx page. The user enters his username-password at Masterpage.

I want to prevent the load of the contentplaceholder, if the user enters wrong username&password combination. Currently I am just disabling it's visibility, which does the trick but the page is still loaded, goes to database etc. which is useless since all of them will not be shown anyway.

You can load the Controls 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);
}

Dynamically added controls need to be recreated on every Page_load (that includes PostBack). So always call buildControls() when a user is logged in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM