提交按钮之前的asp.net文本区域回发

发布于 2024-11-29 16:42:54 字数 624 浏览 3 评论 0原文

我有一个 ASP.NET 表单,底部有一些控件和一个提交按钮,全部位于更新面板内:

<asp:UpdatePanel runat="server" ID="upContent">
    <ContentTemplate>
        <asp:TextBox runat="server" ID="tbxMyTextBox" AutoPostBack="true" />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="return doStuff()" OnClick="btnSubmit_Click" />
    </ContentTemplate>
</asp:UpdatePanel>

如果我在文本框中写入内容并立即单击“提交”(无需先单击文本框),则更改不会被记录(如服务器端事件处理程序中所示)。但是,如果我在 TextBox 中写入一些内容,然后将焦点更改到另一个控件,则通过 UpdatePanel 发生 AutoPostback,然后单击“提交”确实会识别这些更改。如何在单击提交按钮时强制此内容立即更新,同时仍然运行附加到它的客户端和服务器端事件?谢谢!

I have an ASP.NET form with a few controls and a submit button at the bottom, all inside an update panel:

<asp:UpdatePanel runat="server" ID="upContent">
    <ContentTemplate>
        <asp:TextBox runat="server" ID="tbxMyTextBox" AutoPostBack="true" />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="return doStuff()" OnClick="btnSubmit_Click" />
    </ContentTemplate>
</asp:UpdatePanel>

If I write something in the TextBox and click 'submit' immediately (without clicking out of the TextBox first), the changes are not recorded (as seen in the server-side event handler). However, if I write something in the TextBox, and then change focus to another control, an AutoPostback happens through the UpdatePanel and then clicking 'submit' does recognize these changes. How can I force this content to update right as I click the submit button, while still running both the clientside and serverside events attached to it? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

帅气尐潴 2024-12-06 16:42:54

由于某些提交/点击事件处理程序,您的文本框是否可能被清除?我建议您使用一些工具(例如 Fiddler)来检查请求中的 POST 数据。或者,您可以在服务器端代码处放置断点并检查请求数据。特别查找 Request.Form[tbxMyTextBox.UniqueID] - 即查找文本框名称是否存在值(客户端的 name 属性对应于 UniqueID 属性)服务器端)。如果请求包含在文本框中键入的值,则服务器端会发生某些情况,但好消息是您始终可以从请求对象中检索该值。如果该值不存在于 Request 对象中,则意味着客户端代码在提交之前清除该值。

Is is possible that your text-box gets cleared due to some on-submit/on-click event handler? I will suggest you do use some tool such as Fiddler to inspect the POST data in request. Or you can put a break-point at your server side code and inspect the request data. Look for particularly Request.Form[tbxMyTextBox.UniqueID] - i.e. look for presence of value for your text-box's name (name property at client side which corresponds to UniqueID property at server side). If the request contains the value typed in the text-box then something is happening on server side but good news is you can always retrieve the value from Request object. If the value is not present in the Request object then it means that client side code is clearing the value before the submit.

那支青花 2024-12-06 16:42:54

如果 onclick 方法返回 false,它将取消按钮通常执行的操作。由于您的按钮通常会提交表单,但它似乎没有提交,因此 doStuff 中的客户端 JavaScript 代码可能返回 false。

If an onclick method returns false, it cancels the action that the button would normally perform. As your button would normally submit your form, but it appears not to be submitting, your client side javascript code in doStuff is probably returning false.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文