Thursday, February 12, 2009

this._postBackSettings.async is null or not an object

You are using a PopupControlExtender from the AjaxControlToolkit and you added a Button or an ImageButton in it and every time you click on it this ugly js error appears: this._postBackSettings.async is null or not an object. You Google and you see that the solution is to use a LinkButton instead of a Button or an ImageButton.

Well, I want my ImageButton! Therefore I added to the Page_Load method of my page or control this little piece of code to fix the bug:
private void FixPopupFormSubmit()
{
var script =
@"if (window.Sys&&Sys.WebForms&&Sys.WebForms.PageRequestManager&&Sys.WebForms.PageRequestManager.getInstance) {
var prm=Sys.WebForms.PageRequestManager.getInstance();
if (prm&&!prm._postBackSettings) prm._postBackSettings=prm._createPostBackSettings(false, null, null);
}";
ScriptManager.RegisterOnSubmitStatement(Page, Page.GetType(), "FixPopupFormSubmit", script);
}


Hope it helps you all.

11 comments:

Anonymous said...

Thanks a ton!

Chris said...

Thanks mate! Your post just saved me from going insane!

Anonymous said...

I guess it is better than nothing, but I get really agitated when I inherit code from someone and it has voodoo it like this.

Anonymous said...

thanks, it just gets fixed

Rolf said...

This solved my problem. All the other "solutions" are like scrounging around in the dark.

Anonymous said...

Loved it. Great !! boss.

zabanet said...

Brilliant! Saved me lots of time I guess ;)

Sanjay Ror said...

Thanks a lot !
You are a life Saver Man..........

frikz said...

Yes, this was a massive help. Thank you!

Unknown said...

Thanks a lot dear !
It's really helpful...

Anonymous said...

Thanks a lot It worked .....