How to eliminate racing conditions for elements with autopostback=true in ASP.NET?
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 /&g开发者_JS百科t;
<UpdatePanel>
<TextBox AutoPostBack="True" />
<Button />
</UpdatePanel>
</form>
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.
精彩评论