Change Master Page Label Text in from Content Page.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sweetneel
    New Member
    • Oct 2008
    • 42

    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: "masterpagelabe l";

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

    My code is:

    Code:
    void Page_Load(...........)
    Label mylabel=(Label)Master.FindControl("masterpagelabel")
     
    if(mylabel !=Null)
    {
     mylabel="Details";
    }
    else
    {}
    Last edited by Curtis Rutland; Jan 13 '09, 01:08 PM. Reason: please use [CODE] tags when posting code
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    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.mast er.cs
    Code:
    public string MasterPageLabel
    {
      get { return masterpagelabel.Text; }
      set { masterpagelabel.Text = value; }
    }
    Then, add this directive to the top of your content page, right below the @Page directive:
    content.aspx
    Code:
    <%@ MasterType VirtualPath="~/MasterPage.master" %>
    Now you should be able to access the property you just added:
    content.aspx.cs
    Code:
    Master.MasterPageLabel = "some text";
    Remember to change the path "MasterPage.mas ter" to whatever name you were using.

    Comment

    Working...