Asked by:
ASP TextBox type number loses value after postback

Question
-
User1099429166 posted
Dear All,
I have a simple TextBox:<asp:TextBox runat="server" ID="tbText" MaxLength="3" Width="80" type="number"> </asp:TextBox>
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 attributetype="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.
https://stackoverflow.com/a/18283868.
Here a simple demo:
Aspx: <div> <asp:TextBox runat="server" ID="tbText" MaxLength="3" Width="80" type="number"> </asp:TextBox> <br /> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> <br /> <asp:Label ID="Label1" runat="server"></asp:Label> </div> Aspx.cs: protected void Button1_Click(object sender, EventArgs e) { Label1.Text = tbText.Text; }
The result:
Best regards,
Sam
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"> <ContentTemplate> <asp:TextBox ID="TextBox1" runat="server" type="number" MaxLength="3" Width="80"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" /> </ContentTemplate> </asp:UpdatePanel> <asp:Button ID="Button2" runat="server" Text="Button" /> </form>
The result.
Could you provide more code to let us reproduce your problem?
Best regards,
Ackerly Xu
Tuesday, May 21, 2019 2:58 AM