Accessing Master page control in ascx file

后端 未结 4 1715
我寻月下人不归
我寻月下人不归 2021-01-15 03:03

I have a master page file that contains a 2 menu\'s in a 2 panel controls. I also use a control to check if user is logged in and get the type of user.

Deppending on

4条回答
  •  别那么骄傲
    2021-01-15 03:44

    Here's how I do something similar and it works fine:

    if (Page.Master != null)
    {
        var tempPanel = Page.Master.FindControl("MessagePanel") as UpdatePanel;
        if (tempPanel != null)
            tempPanel.Visible = true;
    
    
        var temp = Page.Master.FindControl("MessageForUser") as MessageToUser;
        if (temp != null)
            temp.PostWarningMessage(message, msgInterval);
    }
    

    However, I have "MessagePanel" and "MessageForUser" as controls right above the ContentPlaceHolder. Here's my markup:

    
        
              
            

    If you have your Panel inside of a tag, then you should be able to reference the panel without needing Page.Master.FindControl.

提交回复
热议问题