Dropdownlist in Updatepanel does not work (play nice) in Sharepoint 2007 webpart

Why Can Fail?!

Put a dropdownlist into an AJAX Updatepanel inside a user control to suppress page refreshes during postbacks. Put that user control into a apsx page, works perfectly. Put that same user user control into a Sharepont 2007 webpart, the AJAX UpdatePanel fails to function as expected and we see ugy page refreshes.

Why Like That?!

From Microsoft, it is what they say.

“This issue occurs because both Windows SharePoint Services and ASP.NET AJAX cache some types of form actions. Therefore, conflicts may occur.”

A better explanation from Mike Ammerlaan:

“Windows SharePoint Services JavaScript has a “form onSubmit wrapper” which is used to override the default form action.  This work is put in place to ensure that certain types of URLs, which may contain double byte characters, will fully work across most postback and asynchronous callback scenarios.  However, if your scenarios do not involve double byte character URLs, you may successful disable this workaround and gain the ability to use ASP.NET AJAX UpdatePanels.”

What To Do?!

This is the workaround from the blogs.

Register a client startup script which disables this workaround, in addition to resetting the default form action:

<script type=’text/javascript’>_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;</script>
Embed the startupScript into the Page or user control that uses the UpdatePanel. e.g.
private void EnsureUpdatePanelFixups()
{
if (this.Page.Form != null)
{
string formOnSubmitAtt = this.Page.Form.Attributes[“onsubmit”];
if (formOnSubmitAtt == “return _spFormOnSubmitWrapper();”)
{
this.Page.Form.Attributes[“onsubmit”] = “_spFormOnSubmitWrapper();”;
}
}

ScriptManager.RegisterStartupScript(this, typeof(AjaxUpdatePanelPart), “UpdatePanelFixup”, “_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;”, true);
}

Where Got Say?!

Information gleamed from these sources:

http://sharepoint.microsoft.com/blogs/mike/Lists/Posts/Post.aspx?ID=3

http://www.marten-online.com/sharepoint/ajax-second-postback-not-working-in-sharepoint-in-updatepanel.html

http://bloggingabout.net/blogs/rick/archive/2008/03/21/dropdownlist-selectedindexchanged-doesn-t-trigger-updatepanel-in-sharepoint-2007-sp1.aspx

Wordy MS explanation:

http://support.microsoft.com/kb/941955

This issue occurs because both Windows SharePoint Services and ASP.NET AJAX cache some types of form actions. Therefore, conflicts may occur.
Advertisements

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: