Problem using Label in MasterPage

Last post 05-09-2008 4:50 PM by hermiod. 8 replies.

Sort Posts:

  • Problem using Label in MasterPage

    04-22-2008, 9:44 AM

     Hello folks,

    This is my problem. I have put a Label (it is called Label1) in my Masterpage and I´ve configured as not visible at the beginning. I have a file called "ChooseNumber.aspx". In this file there´s button and when is pressed I want to make the label visible first and also give a value to it. But in "ChooseNumber.aspx" file I don´t have access to this component because they are in different programs. What advice to you give me to solve my problem?

    Thank you very much. 

  • Re: Problem using Label in MasterPage

    04-22-2008, 10:00 AM
    Answer
    • Loading...
    • shayas
    • Joined on 02-06-2008, 12:42 PM
    • Sharjah,UAE
    • Posts 214

    expose the label as public property in the master apge and then

    add the below to content aspx

    <%@ MasterType VirtualPath="[urmasterpage path]" %>

    and then u can access label using

    Master.urlabelproperty

     

    Yasser
    R&D Dept.
    Industry Networks.

    Please remember to mark as answers if this helps
  • Re: Problem using Label in MasterPage

    04-22-2008, 10:16 AM

     Thanks for the information.

    Just a question: how do I make the label public?
     

  • Re: Problem using Label in MasterPage

    04-22-2008, 11:17 AM
    Answer
    • Loading...
    • hermiod
    • Joined on 08-30-2007, 8:31 AM
    • Posts 71

    I believe Shavas meant create a public property accessible from the content page which can then be used to alter the text of the private label. Something like this:

    Public Property MasterLabel() as string
    Get
      Return
    MyLabel.Text
    End Get
    Set
    (ByVal value As String)
      Mylabel.Text=Value
      MyLabel.Visible=True
    End Set
    End Property

     You can then access this property from your Content page like so.

    Master.MasterLabel = "Whatever text I want to put in my label"

     

    Hope this solves your problem.

    Please Mark As Answer if this post helped you.
  • Re: Problem using Label in MasterPage

    05-09-2008, 9:34 AM

    hermiod:

    I believe Shavas meant create a public property accessible from the content page which can then be used to alter the text of the private label. Something like this:

    Public Property MasterLabel() as string
    Get
      Return
    MyLabel.Text
    End Get
    Set
    (ByVal value As String)
      Mylabel.Text=Value
      MyLabel.Visible=True
    End Set
    End Property

     You can then access this property from your Content page like so.

    Master.MasterLabel = "Whatever text I want to put in my label"

     

    Hope this solves your problem.

     

     

    I´ve tried to write your code but doesn´t recognize the function. I´ve written  <%@ MasterType VirtualPath="~/AppMaster.master"%> in my aspx file. I´ve written the code above in MasterPage.master.cs file in this way:

    public string MasterLabel
        {
            get {return Label1.Text;}
            set {Label1.Visible=true; Label1.Text="parameter that this function receives";}
        }

    I want to pass an argument to this function (the text the label will show) but oesn´t accept any argument and if I write an argument get and set properties are not recognized.

    No idea what´s wrong. Please help!
     

  • Re: Problem using Label in MasterPage

    05-09-2008, 11:39 AM
    • Loading...
    • hermiod
    • Joined on 08-30-2007, 8:31 AM
    • Posts 71

    I'm not familiar with C# so this may be the same as what you've already got but try this...

     

    public string MasterLabel {
        get { return MyLabel.Text; }
        set {
            Mylabel.Text = value;
            MyLabel.Visible = true;
        }
    }

     Its a direct conversion from the code I posted.

    I don't know if there is something different between C# and VB.Net but you should be able to just do Master.MasterLabel = "hello jello". Perhaps a C# expert could weigh in with a little help if this doesn't solve it...?

    EDIT: Try adding the following into your @page directive as well as the @MasterType you already have..

     MasterPageFile="~/Reports.master"

    It's straight after Language in mine.

    Please Mark As Answer if this post helped you.
  • Re: Problem using Label in MasterPage

    05-09-2008, 11:54 AM

     Hi hermiod,

    hermiod:

    EDIT: Try adding the following into your @page directive as well as the @MasterType you already have..

     MasterPageFile="~/Reports.master"

    It doesn´t recognize MasterPageFile in @page directory.

    Anyway, thank you very much hermiod. I hope a c# expert will help me with this.

     

  • Re: Problem using Label in MasterPage

    05-09-2008, 11:56 AM

    basquepower:
    It doesn´t recognize MasterPageFile in @page directory.
     

    Sorry I wanted to say that doesn´t recognize Report.master in MasterPageFile . 

  • Re: Problem using Label in MasterPage

    05-09-2008, 4:50 PM
    • Loading...
    • hermiod
    • Joined on 08-30-2007, 8:31 AM
    • Posts 71

    Sorry I should've been clearer on that, Change 'Reports.master' to the name of your master file.

    Please Mark As Answer if this post helped you.
Page 1 of 1 (9 items)