asp.net textbox doesn't populate after postbac

2019-03-03 20:17发布

问题:

I am using ASP.NET and C# couple text boxes to calculate results entered. Textbox2 has a value entered and on button click Textbox1 gets populated. This works fine the first time I enter the value. But the second time I change the value in Textbox2, I see that the value is being assigned to Textbox1 while debugging on Button click, but doesn't show up on the screen. I have many other controls and a master page. The textboxes are within an update panel.

Can someone help me what's going on?

Here is the code:

<asp:TextBox ID="Textbox1" runat="server" Width="150px"   TabIndex="6" MaxLength="8"></asp:TextBox>                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="TextBox1" ErrorMessage="*"></asp:RequiredFieldValidator>

<asp:TextBox runat="server" ID="Textbox2" Width="150px" Visible="false"></asp:TextBox>&nbsp

<asp:ImageButton runat="server" ID="imgCalcAdjRate" ImageUrl="~/Resource/Images/calrate_0.bmp" onmouseout="this.src='../Resource/Images/calrate_0.bmp'" onmouseover="this.src='../Resource/Images/calrate_1.bmp'"                    Height="25px" Width="25px" Visible="false" onclick="imgCalcAdjRate_Click" /> 

回答1:

Check the postback in the page_load function.

if(!Page.IsPostBack) {

}

I think you are loosing information on post back. The data is changed, but it get reset on post back.