469,625 Members | 1,702 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

Change Master Page Label Text in from Content Page.

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")
  4. if(mylabel !=Null)
  5. {
  6.  mylabel="Details";
  7. }
  8. else
  9. {}
Jan 13 '09 #1
1 18035
Curtis Rutland
3,256 Expert 2GB
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:
Expand|Select|Wrap|Line Numbers
  1. <%@ MasterType VirtualPath="~/MasterPage.master" %>
Now you should be able to access the property you just added:
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.

Similar topics

2 posts views Thread by archana | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.