Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:46am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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  
v5
Comments
Krunal Rohit at 4-Nov-12 8:59am
   
Na,its not working...
ProgramFOX at 4-Nov-12 9:06am
   
Ok, I updated my answer.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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 at 4-Nov-12 9:18am
   
Still its not working. :(
nkkppp at 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)

  Print Answers RSS
0 CHill60 330
1 OriginalGriff 285
2 CPallini 198
3 BillWoodruff 170
4 Sergey Alexandrovich Kryukov 168


Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 4 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100