【问题标题】:How To Update TextBox using Update panel in asp.net如何使用 asp.net 中的更新面板更新文本框
【发布时间】:2011-05-05 11:15:00
【问题描述】:

我在UpdatePanel 外面有一个TextBox,在Updatepanel 里面有一个Button 当我点击Button 时,它会在TextBox 中显示值。

我已经编写了以下代码。

<%@ 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>

---------代码背后---------

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

【问题讨论】:

    标签: asp.net ajax updatepanel


    【解决方案1】:

    您的文本框值在您将其放入更新面板之前无法更新。

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

    或者,如果您注册按钮的触发器并将按钮从更新中拉出会更好,例如...

    <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>
    

    【讨论】:

    • 是的,我已经告诉过你,该值仅在该特定控件位于更新面板中时才会更新。
    猜你喜欢
    • 2017-08-07
    • 1970-01-01
    • 2016-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-23
    相关资源
    最近更新 更多