Click here to Skip to main content
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 3:46am
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.
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.

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

  Print Answers RSS
0 OriginalGriff 406
1 /\jmot 180
2 Suraj Sahoo | Coding Passion 170
3 Afzaal Ahmad Zeeshan 159
4 BillWoodruff 154
0 OriginalGriff 8,344
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,634
3 Maciej Los 5,024
4 Manas Bhardwaj 4,986

Advertise | Privacy | Mobile
Web02 | 2.8.1411023.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