By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,505 Members | 1,034 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,505 IT Pros & Developers. It's quick & easy.

Change Master Page Label Text in from Content Page.

P: 42
Hi, all

In my Asp.net application, I have A Master Page, which has a Label & its id is: "masterpagelabel";

now i want to change the Text of this Label When the Content Page Loads

My code is:

Expand|Select|Wrap|Line Numbers
  1. void Page_Load(...........)
  2. Label mylabel=(Label)Master.FindControl("masterpagelabel")
  3.  
  4. if(mylabel !=Null)
  5. {
  6.  mylabel="Details";
  7. }
  8. else
  9. {}
Jan 13 '09 #1
Share this Question
Share on Google+
1 Reply


Curtis Rutland
Expert 2.5K+
P: 3,256
OK, here's what you can do. In your master page's codebehind, expose a public property that gets and sets the label.
For example:
in MasterPage.master.cs
Expand|Select|Wrap|Line Numbers
  1. public string MasterPageLabel
  2. {
  3.   get { return masterpagelabel.Text; }
  4.   set { masterpagelabel.Text = value; }
  5. }
Then, add this directive to the top of your content page, right below the @Page directive:
content.aspx
Expand|Select|Wrap|Line Numbers
  1. <%@ MasterType VirtualPath="~/MasterPage.master" %>
Now you should be able to access the property you just added:
content.aspx.cs
Expand|Select|Wrap|Line Numbers
  1. Master.MasterPageLabel = "some text";
Remember to change the path "MasterPage.master" to whatever name you were using.
Jan 13 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.