Rick van den Bosch - Blog

... on .NET, software architecture, software development and whatnot

DropDownList SelectedIndexChanged doesn't trigger UpdatePanel in SharePoint 2007 SP1

A week ago I had a nice page that was hosted in SharePoint and, among others, contained an updatepanel with a dropdownlist in it. Everything worked, and all was well. Because our testers had found some issues we had delivered two newer versions to our development environment. In the last version they found an issue that wasn't there before: selecting a different value in the dropdown did not only update the updatepanel, but resulted in a complete postback. My first idea was: that's an easy one, I'll check the triggers. Boy, was I wrong...

A few hours later, we had everything working again. But rebuilding the entire usercontrol didn't solve the issue, and neither did changeing all available settings for all controls ;). Weird thing was it did work when outside of a SharePoint environment. After some extensive searching, I found a post on Brian H. Madsen's blog, called Using DropDownList with an UpdatePanel in MOSS 2007. As it turns out, SP1 introduces a bug for working with dropdownlists, making that the SelectedIndexChanged event isn't captured by the update panel. Brian's post contains the code below which, if placed in the page_load, solves this issue:

if (this.Page.Form != null)
{
    if (this.Page.Form.Attributes["onsubmit"] == "return _spFormOnSubmitWrapper();")
    {
        this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
    }
}

ScriptManager.RegisterStartupScript(this, this.GetType(), "UpdatePanelFixup",
    "_spOriginalFormAction = document.forms[0].action;_spSuppressFormOnSubmitWrapper=true;", true);

Comments

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# April 11, 2008 4:01 PM

Morris said:

I'm new at integrating ajax with sharepoint but your topic is exactly what's happening with my site.

I've created a webpart and my controls are added to the updatepanel.  Within the class I've created a handler for the onclick event of a button.  The event is been fired but the page (Master page) in sharepoint does not refresh with the changes caused by the click event.

Also, I'm using the SelectedIndexChanged event to populate dropdownlists.  When I select an item in the list the page does a full refresh.  These controls are also added to the updatepanel.  They show up on the page in sharepoint but do not function properly.  Your code example is simple.  I'm using vb.net and in my class I don't have access to the page_load event.  Would you mind pointing me in the right direction?

regards,

amorris01@yahoo.com

# April 30, 2008 7:39 PM

Loki said:

It really worked with the updatepanel and can u please let me know how to apply triggers concept of ajax to the sharepoint.Is some code need to be added to the Page load event to apply triggers concept?

# July 8, 2008 7:01 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)