Keep label value in the master page

Last post 10-29-2009 2:11 PM by elbasha. 7 replies.

Sort Posts:

  • Keep label value in the master page

    10-28-2009, 9:27 PM
    • Member
      84 point Member
    • elbasha
    • Member since 09-23-2008, 6:05 PM
    • Florida, USA
    • Posts 340

    Hello,

    I have a content page where a value will be transfered from there into the master page, I got that part to work but as soon as I refresh the page or go to any other page that value in the label is gone.  How do I go about keeping that value in the label?

  • Re: Keep label value in the master page

    10-29-2009, 12:41 AM
    • Member
      656 point Member
    • tecktree
    • Member since 05-15-2009, 7:57 AM
    • Posts 141

    Hi,

    Try using Viewstate (to store the values within a single page) or session (to store the values throughout the application) to store the label value and pass these stored values to the label


    ---------Varun---------
  • Re: Keep label value in the master page

    10-29-2009, 12:51 AM
    Answer
    • Member
      240 point Member
    • rajeev16mca2k5
    • Member since 05-11-2009, 12:50 PM
    • New Delhi
    • Posts 65

    keep the value that has to be set in  a session variable and set it in master page's page_load event.

    Remember to click “Mark as Answer” on the post, if it helps you. Because It helps others to find the solution.


    Rajeev Singh Chib
    +91-9899816577, +91-9906297214
    rajeev16mca2k5@gmail.com
    India Flag smiley 73
  • Re: Keep label value in the master page

    10-29-2009, 1:01 AM
    • Member
      288 point Member
    • dude_123
    • Member since 10-04-2009, 8:09 AM
    • Posts 68

    Use session variable in the master page code behind

  • Re: Keep label value in the master page

    10-29-2009, 1:01 AM
    • Member
      188 point Member
    • binli0114
    • Member since 09-26-2006, 12:31 AM
    • Sydney
    • Posts 48

    if that is sensitive data and only available to the Authorization User

    then i would recommend that put the data in Ticket.UserData

     FormsAuthentication.Initialize();
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                1, Username, DateTime.Now, DateTime.Now.AddDays(1), false,
                [Your Data], FormsAuthentication.FormsCookiePath);
            string hash = FormsAuthentication.Encrypt(ticket);
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
            HttpContext.Current.Response.Cookies.Add(cookie);


    ------------------------------------------------------------
    I LOVE THIS GAME
  • Re: Keep label value in the master page

    10-29-2009, 2:43 AM
    • Participant
      1,191 point Participant
    • Mohammed Askar
    • Member since 09-01-2009, 8:23 AM
    • Sri Lanka
    • Posts 290

    In your Master page declare Public property Like this


    private  string _labelDesc ;


    Public string SetLabel

    {

       set { ViewState["LabelDesc"] = labelDesc;}

       get { return (string)  ViewState["LabelDesc"] ;  }

    }


    Now you can set value in you label

    Label.Text = _labelDesc;


    Please mark as answered, if this help you.
  • Re: Keep label value in the master page

    10-29-2009, 2:57 AM
    • Member
      320 point Member
    • Rakeshkr
    • Member since 10-09-2009, 10:55 AM
    • Bangalore
    • Posts 76

    Hi,

    Craete properties in Master page like

    /// <summary>
        /// 
        /// </summary>
        public string SubMenu
        {
            get { return lblSubMenu.Text; }
            set { lblSubMenu.Text = value; }
        }

        public string SubMenu

        {

            get { return lblSubMenu.Text; }

            set { lblSubMenu.Text = value; }

        }


    and set value from other page in page load event

    MaterPage_Header m = (MaterPage_Header)Page.Master;

            m.SubMenu = "SubUsers Details";

  • Re: Keep label value in the master page

    10-29-2009, 2:11 PM
    • Member
      84 point Member
    • elbasha
    • Member since 09-23-2008, 6:05 PM
    • Florida, USA
    • Posts 340

    I am using VB.NET,

    Can you show me some sample via VB.NET please? Sorry I didn't state that earlier, I have the following in the master page:


    Public Property SubMenu() As String
            Get
                Return lblCustomerID.Text
            End Get
            Set(ByVal Value As String)
                lblCustomerID.Text = Value
            End Set
        End Property


    Now how do I go about calling it from the regular page?

Page 1 of 1 (8 items)