ASP.NET:

<asp:UpdatePanel runat="server" ClientIDMode="Static" ID="upReg" UpdateMode="Conditional">
    <ContentTemplate>
        <input id="txtSecNum" type="password" name="RSecNum" value="" placeholder="####" runat="server" maxlength="4" />
        <asp:Label Text="" runat="server" ID="lblRSecNum" CssClass="lblStyle noDisplay" />

        <asp:Button ID="btnRegister" ClientIDMode="Static" runat="server" Text="Register" OnClick="btnRegister_Click" />
    </ContentTemplate>
</asp:UpdatePanel>

C#:

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        if (Session["TheSecNum"] != null) //does not execute which is correct
        {
            MessageBox.Show(Session["TheSecNum"].ToString());
        }
    }
    else
    {
        Session["TheSecNum"] = txtSecNum.Value;

        MessageBox.Show(Session["TheSecNum"].ToString()); //displays the number

        if (Session["TheSecNum"] != null)
        {
            txtSecNum.Attributes.Add("value", Session["TheSecNum"].ToString()); //when debugging it shows that the textbox is being populated
        }
    }
}

public void btnRegister_Click(object sender, EventArgs e)
{
    if (txtSecNum.Value == "")
    {
        lblRSecNum.Text = "Please enter number";
    }
    else
    {
        if (txtSecNum.Value.Length < 4)
        {
            lblRSecNum.Text = "Please enter four digit";
        }
        else
        {
            lblRSecNum.Text = "";
        }
    }
    upReg.Update();
}

When the page (part of the page refreshes with the updatepanel) refreshes, the textbox goes back to displaying #### and not the saved value.

Please help me resolve the issue.

Related posts

Recent Viewed