How To Update TextBox using Update panel in asp.net

 ̄綄美尐妖づ 提交于 2019-12-25 02:20:00

问题


I Have a TextBox outside the UpdatePanel and a Button inside the Updatepanel When i click on the Button it show value in TextBox.

I Have Write Following Code.

<%@ Register TagPrefix="AjaxToolKit" Assembly="AjaxControlToolkit"         
    Namespace="AjaxControlToolkit" %>


<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" 
         EnablePageMethods="true" />
    <asp:TextBox ID="TextBox5" runat="server" />
    <asp:UpdatePanel runat="server" ID="Up1">
       <ContentTemplate>
           <asp:Button ID="btn" runat="server" onclick="btn_Click" />
       </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

----------Code Behind---------

protected void btn_Click(object sender, EventArgs e)
{
    TextBox5.Text = "20000";
}

回答1:


Your textbox value can't be updated untill you put it in an update panel.

<ContentTemplate>
  <asp:TextBox ID="TextBox5" runat="server" />
  <asp:Button ID="btn" runat="server" onclick="btn_Click" />
</ContentTemplate>

OR, it would be better if you register a trigger of the button and pull your button out from your update, like...

<asp:UpdatePanel runat="server" ID="upnl" UpdateMode="Conditional" >
<ContentTemplate>
    <asp:TextBox ID="TextBox5" runat="server" />
</ContentTemplate>
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="btn" EventName="Click" />
</Triggers>
</asp:UpdatePanel>


来源:https://stackoverflow.com/questions/5896807/how-to-update-textbox-using-update-panel-in-asp-net

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