Click here to Skip to main content
Sign Up to vote bad
good
See more: C#ASP.NET
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 4 Nov '12 - 2:46


3 solutions

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.
  Permalink  
Comments
Krunal Rohit - 4 Nov '12 - 8:59
Na,its not working...
ProgramFOX - 4 Nov '12 - 9:06
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.
  Permalink  
Comments
Krunal Rohit - 4 Nov '12 - 9:18
Still its not working. :(
nkkppp - 4 Nov '12 - 9:21
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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 393
1 OriginalGriff 335
2 Arun Vasu 315
3 Maciej Los 238
4 Aarti Meswania 180
0 Sergey Alexandrovich Kryukov 9,680
1 OriginalGriff 7,539
2 CPallini 4,018
3 Rohan Leuva 3,362
4 Maciej Los 2,951


Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 4 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid