Click here to Skip to main content
14,698,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all, I am trying to interact with Master Page controls from its Content Page...

In content page I have included this :
<%@ MasterType VirtualPath="~/MasterPage.Master" %>


and this is the code behind Home.aspx.cs (on page load event) :
protected void Page_Load(object sender, EventArgs e)
        {
            if (Session.Count > 1)
            {
                //Label lbl = Master.FindControl("userloginstatuslabel") as Label;
                //lbl.Visible = true;

                HyperLink link = Master.FindControl("loginlink") as HyperLink;
                link.Text = "Log Out";
            }


        }


Though I have done this, text of Link not changed..

Help me with appropriate solution..
Posted

You can try to don't add
<%@ MasterType VirtualPath="~/MasterPage.master" %>

But to add a MasterPageFile attribute to your @Page directive:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" %>

Hope this helps.
   
v5
Comments
Krunal Rohit 4-Nov-12 8:59am
   
Na,its not working...
Thomas Daniels 4-Nov-12 9:06am
   
Ok, I updated my answer.
Hi,

FYI,while using Master.FindControl method no need to write the Mastertype directive.

As per the code provided by you there is no error.It shud work perfectly.

Please check where if (Session.Count > 1) is working or not, place a debug.

If still not working.Let me know.

Regards,
Prathap.
   
Comments
Krunal Rohit 4-Nov-12 9:18am
   
Still its not working. :(
Prathap Gangireddy 4-Nov-12 9:21am
   
Can you provide the Master page html content.

Try to access the control without using Session.Count>1 condition.If this is working fine then there might be some prob with Session.Count.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900