Accessing Label Control on OnInit

Discussion in 'C#' started by webcosmo, Jul 17, 2007.

  1. #1
    I have a lable control on the page which has EnableViewState=false.
    Also a button.
    When I click on the button a text is shown dynamically on the label.
    Since page has viewstate false, label text is lost when some other button clicked.
    I tried to get the PostBack value of the label in the OnInit function but looks like its empty.
    Anybody?
     
    webcosmo, Jul 17, 2007 IP
  2. MasterOfLogic

    MasterOfLogic Well-Known Member

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #2
    i can help you.. post your code, you're not really giving people enough to go on here. also, try the official asp.net forums if people can't help you here.
     
    MasterOfLogic, Jul 17, 2007 IP
  3. webcosmo

    webcosmo Notable Member

    Messages:
    5,840
    Likes Received:
    153
    Best Answers:
    2
    Trophy Points:
    255
    #3
    I solved it. Here is it. I just gonna use shorthand.
    <form>
    <asp:label id="lbl" runat="server"/>
    <asp:button id="btn1" onclick="showdata"/>
    <asp:button id="btn2" Text="refresh"/>
    </form>

    protected void btnShowAdmin_Click(object sender, System.EventArgs e)
    {
    lbl.Text="hello there.";
    Page.ClientScript.RegisterHiddenField("hidField", lbl.Text);

    }

    protected override void OnInit(EventArgs e)
    {
    if (Request["hidField"] != null)
    {
    lbl.Text = Request["hidField"];
    Page.ClientScript.RegisterHiddenField("hidField", Request["hidField"]);
    }
    }
     
    webcosmo, Jul 17, 2007 IP