如何在 asp.net 中使用更新面板更新文本框

编程入门 行业动态 更新时间:2024-10-09 23:16:07
本文介绍了如何在 asp 中使用更新面板更新文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

I Have a TextBox outside the UpdatePanel and a Button inside the Updatepanel When i click on the Button it show value in 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>

----------代码隐藏---------

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

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

推荐答案

除非您将文本框值放入更新面板,否则无法更新它.

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>

这篇关于如何在 asp 中使用更新面板更新文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-28 15:33:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1175416.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   面板   如何在   net   asp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!