如何消除 ASP.NET 中 autopostback=true 元素的竞争条件?
我们使用 Sharepoint 进行开发,因此我们必须坚持使用 ASP.NET 3.5。 如果我们的页面有带有自动回发的字段和一个按钮,一旦用户位于自动回发字段并单击按钮,我们就会遇到竞争条件。 在这种情况下,按钮单击有时会比自动回发早返回,因此会被覆盖。
以前有人遇到过这个问题吗?
什么是正确的解决方案?
添加在: 我说的这个案例是关于以下内容的:
<form>
<ScriptManager />
<UpdatePanel>
<TextBox AutoPostBack="True" />
<Button />
</UpdatePanel>
</form>
We develop using Sharepoint, therefore we have to stick to ASP.NET 3.5.
In case if our page have field with autopostback and a button we encounter race conditions as soon as user was on autopostback field and clicks the button.
In this case button click sometimes returns earlier than autopostback’s one and therefore is being overridden.
Did anyone experience this issues before?
What is the right solution for it?
ADDON:
The case I'm talking about is about the following:
<form>
<ScriptManager />
<UpdatePanel>
<TextBox AutoPostBack="True" />
<Button />
</UpdatePanel>
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能想到的最基本的解决方案是通过处理导致自动回发的客户端事件来使用 javascript 禁用按钮。
The most basic solution I can think of is to disable the button using javascript by handling the client event that's causing the autopostback.
您可以在等待回发时禁用该按钮。但这是一种黑客行为,您可能不想这样做。通常,我希望控件能够进行验证并在出现问题时阻止提交。
假设您在下拉框中有一个自动回发,在某些情况下它会切换某些子类别信息的文本框。要么发生自动回发并首先更新文本框,要么提交将使用下拉列表的新值提交,并且服务器端验证将确定您是否需要在该子文本框中包含值。如果你这样做了,它会返回并启用它,并且可能会出现一些红色文本说明这是必需的。
You could disable the button while waiting on the postback. But that's a hack and you probably don't want to do that. Typically, I'd expect that the controls would do their validation and block the submission if there's a problem.
Let's say you had an autopostback on a drop-down box where it toggles a textbox for some sub-category info in certain cases. Either the autopostback happens and updates the textbox first, or the submit will submit with the new value of the drop-down and the server-side validation will determine if you needed to have a value in that sub-textbox. If you did, it would return with it enabled and possibly some red text saying it's required.