Click here to Skip to main content
11,581,982 members (75,271 online)
Rate this: bad
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
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.
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
Please Sign up or sign in to vote.

Solution 2


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.

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 OriginalGriff 355
1 Sergey Alexandrovich Kryukov 220
2 Andy Lanng 110
3 virusstorm 109
4 Kornfeld Eliyahu Peter 90
0 OriginalGriff 1,358
1 Sergey Alexandrovich Kryukov 970
2 Abhinav S 671
3 F-ES Sitecore 505
4 Suvendu Shekhar Giri 448

Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 4 Nov 2012
Copyright © CodeProject, 1999-2015
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