ASP TextBox type number loses value after postback RRS feed

  • Question

  • User1099429166 posted

    Dear All,

    I have a simple TextBox:

    <asp:TextBox runat="server" ID="tbText" MaxLength="3" Width="80"  type="number">

    When I add type="number" the control loses its content after a post-back . How can I make the value remain in the TextBox and add the attribute type="number"?

    Monday, May 20, 2019 1:46 AM

All replies

  • User288213138 posted

    Hi  Sam Solomon,

    I tried to reproduce your problem and found that my code worked.

    Please check your version of Asp.net, if you are using ASP.NET 4.0 or newer,  it will be working normally.

    Here's how ASP.NET renders different versions of ASP.NET.



    Here a simple demo:

                <asp:TextBox runat="server" ID="tbText" MaxLength="3" Width="80" type="number">
                <br />
                <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
                <br />
                <asp:Label ID="Label1" runat="server"></asp:Label>
    protected void Button1_Click(object sender, EventArgs e)
                    Label1.Text = tbText.Text;                    

    The result:

    Best regards,


    Monday, May 20, 2019 4:14 AM
  • User1099429166 posted

    Sorry I forgot but my textbox is in update panel

    Monday, May 20, 2019 10:55 AM
  • User-2054057000 posted

    Are you binding the textbox some ways or the other in the page load event?

    Monday, May 20, 2019 11:36 AM
  • User-893317190 posted

    Hi Sam Solomon,

    I tried to put textbox in a updatepanel and post back both in the updatepanel and outside the updatepanel but still couldn't reproduce your problem.

    Below is my code.

    <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <asp:TextBox ID="TextBox1" runat="server" type="number" MaxLength="3" Width="80"></asp:TextBox>
                    <asp:Button ID="Button1" runat="server" Text="Button" />
            <asp:Button ID="Button2" runat="server" Text="Button" />

    The result.

    Could you provide more code to let us reproduce your problem?

    Best regards,

    Ackerly Xu

    Tuesday, May 21, 2019 2:58 AM