Wednesday, March 21, 2012

Partial Postback + Extenders (Blast from the Past...)

This seems rather ironic with the issues concerning the extenders after partial postbacks in the newest release. At work, we are still using the CTP release and have not converted to Beta. I am also having problems with my extenders not working after a partial postback. The current page uses 2 main controls. One is a custom control that contains a textbox, calendar, and popup behavior to encapsulate a popup calendar. The other is a custom autocomplete extender. The javascript events are not being fired. (I've verified this by adding debug statements in the javascript that print out if I remove the UpdatePanel, and do not print out when the UpdatePanel is uncommented.

MasterPage's ContentTemplate
-----PopupCalendar Control
-----Custom AutoComplete

I saw one post saying that it was the table causing the problem and that making the table runat="server" fixed his/her problem. Lucky him/her. If the DetailsView uses DefaultMode="edit", then both controls work. If I start in ReadOnly mode and use a partial postback to

I know that this is an older release, but if anyone has any thoughts or experienced this when they were using the last pre-beta CTP release, I'd really appreciate some help before I rip all of my hair out.


I suspect the problem here is that the UpdatePanel doesn't understand the dynamic loading of the components, which probabaly happens in PreRender after the UpdatePanel has scanned the tree. So when the DetailsView switches modes and popuplates itself, it's too late. Unfortuantely, I'm not sure how to fix it.

One thing you can try is calling DetailsView1.DataBind() in Page_Load.

I had a similar problem with the AccordionExtender in an UpdatePanel and created the following workaround:

1) Get control toolkit source code

2) Add the following class under AjaxControlToolkit\ExtenderBase\ExtendedScriptBehaviorDescriptor.cs:

using System;using System.Collections.Generic;using System.Text;using Microsoft.Web.UI;namespace AjaxControlToolkit.ExtenderBase{/// <summary> /// This is merely a hack to overcome the known limitation of the Ajax 1.0 Beta 2 /// that it is impossible to use control extenders inside UpdatePanel because /// the correspondend Behavior instance is being lost after the async postback. /// The workaround is to register an event handler on page load event of the /// PageRequestManager and to re-create the behaviour in this event handler. /// This class has been only tested for an Accordion control inside UpdatePanel. /// </summary>class ExtendedScriptBehaviorDescriptor: ScriptBehaviorDescriptor {public ExtendedScriptBehaviorDescriptor(string type,string elementID):base(type, elementID) { }protected override string GetScript() {string answer =base.GetScript() +" Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded("+"function (sender, args) {"+" var myBehaviors = Sys.UI.Behavior.getBehaviorsByType($get('" +this.ElementID +"'), " +this.Type +");" +" if(myBehaviors.length == 0) {"+base.GetScript() +" }"+"});";//Known limitation / bug: if you register several extenders of the same type //for the same DOM element, only one of them (anyone) will be re-created //after async postback. Can be easily fixed using a slightly more complex //checking logic in the javascript above.return answer; } }}

3) Find the method GetScriptDescriptors in ExtenderControlBase and change the following:

//Original code (before patch): //ScriptBehaviorDescriptor descriptor = // new ScriptBehaviorDescriptor(ClientControlType, targetControl.ClientID); ExtendedScriptBehaviorDescriptor descriptor =new ExtendedScriptBehaviorDescriptor(ClientControlType, targetControl.ClientID);

4) Compile the control toolkit, reference the new version in your project and try if it works now.

You can use the new class also with extenders not using ExtenderControlBase from the Control Toolkit.

Neat! I've openedwork item 6063 to track this.

Sorry for the delay in replying, I ditched college for the week and went home for Thanksgiving.Wink. Calling DataBind on the DetailsView in the PageLoad event didn't work. Random thought: to match other pages in the project, both the details view and gridview are in the same update panel. I wonder if separating so that the dv and gv each have their own update panel would make a difference.

*starts muttering and switches back to VS.

Edit: If I use DefaultMode="Edit" for the DetailsView, click in the textbox to bring up the popup calendar, and click to advance the month, I get the following:


In the pre-beta CTP, there is no ScriptBehaviorDescriptor, so if this is even a possible hack, it will need to be a hack of a hack. Is there a CTP equivalent?

We recommend using the latest Beta. There may be issues that would require more investigation using the ctp. A lot of changes were made just to get the toolkit working at the ajax beta so it would be best to move to the beta and then pursue this investigation.

No comments:

Post a Comment