asp.net textbox doesn't populate after postback

南笙酒味 提交于 2019-12-02 19:18:55

问题


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.



来源:https://stackoverflow.com/questions/21167476/asp-net-textbox-doesnt-populate-after-postback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!