two events fired simultaneously in ASP.NET
I have an update panel in my ASP.NET web form with a trigger that will fire a click event when the contents within my update panel is updated (it's a grid view with fields). The event that is fired when then take the changes user made and do some calculation and then update another update panel with that information. This is all fine and dandy when the user tabs along the form and fill out the form in a orderly fashion before hitting any buttons on the page.
If a user accidentally hits another button on the page while changing the content in my grid within the update panel, for example, the user enter a value in my grid view control, without tabbing, the user click the save button.
Logically, i believe that the trigger sho开发者_如何学Pythonuld fire the click event first (event A), and then the save button event (event B). But, consistently I haven't seen event A gets fire correctly while event B gets fire all the time ...
any thoughts on this?
is there a way to ensure event A always gets fired before event B? also if event A update another update panel without the page will event B fire after the update is complete?
thanks.
You can try to block the form from post 2 times before gets update. Here is an example
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
var fAlloToSubmit = true;
function AllowFormToRun()
{
if(!fAlloToSubmit)
alert("Please wait for the page to fully re-loaded.");
return fAlloToSubmit;
}
function InitializeRequest(sender, args) {
fAlloToSubmit = false;
}
function EndRequest(sender, args) {
fAlloToSubmit = true;
}
and on code behind add the onsubmit.
protected void Page_Load(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(Page.Form.Attributes["onsubmit"]))
{
Page.Form.Attributes["onsubmit"] = "return AllowFormToRun();";
}
}
精彩评论