DualList dose not work in UpdatePanel

Feb 21, 2008 at 11:06 PM
Edited Feb 21, 2008 at 11:26 PM
Hi,

I am trying to use DualList within an UpdatePanel but the control does not appear to work.
I cannot move items between the lists.
I am aware that there was a similar issue raised in Nov 2007.
Mar 10, 2008 at 6:39 AM
The issue is around the use of Page.ClientScript to register the javascript while in the update panel you need to use the scriptmanager.
This is a great article if you want to make both ways work without a reference to system.web.extensions:
http://forums.asp.net/p/1040033/1445844.aspx
This is an example of updating the duallist control to use the scriptmanger (also need to update DynamicListBox to make it work):

protected virtual void RegisterScript()
{
if ( this.Page != null && !this.AutoPostBack )
{
//ClientScriptManager script = Page.ClientScript;
ScriptManager.RegisterClientScriptResource(Page, typeof(DualList), "MetaBuilders.WebControls.Embedded.DualListScript.js");
//script.RegisterClientScriptResource(typeof(DualList), "MetaBuilders.WebControls.Embedded.DualListScript.js");
ScriptManager.RegisterStartupScript(Page, typeof(DualList), "DualListScript", "MetaBuildersDualListInit(); " + String.Format(Resources.AjaxWorkaroundScript, "MetaBuildersDualListInit"), true);
//script.RegisterStartupScript( typeof( DualList ), "DualListScript", "MetaBuildersDualListInit(); " + String.Format( Resources.AjaxWorkaroundScript, "MetaBuildersDualListInit" ), true );

StringBuilder objInit = new StringBuilder();
objInit.Append( "{ LeftBoxID:'" );
objInit.Append( this.leftBox.ClientID );
objInit.Append( "', " );
objInit.Append( "RightBoxID:'" );
objInit.Append( this.rightBox.ClientID );
objInit.Append( "', " );
objInit.Append( "MoveRightID:'" );
objInit.Append( this.moveRight.ClientID );
objInit.Append( "', " );
objInit.Append( "MoveAllRightID:'" );
objInit.Append( this.moveAllRight.ClientID );
objInit.Append( "', " );
objInit.Append( "MoveLeftID:'" );
objInit.Append( this.moveLeft.ClientID );
objInit.Append( "', " );
objInit.Append( "MoveAllLeftID:'" );
objInit.Append( this.moveAllLeft.ClientID );
objInit.Append( "', " );
objInit.Append( "MoveUpID:'" );
objInit.Append( this.moveUp.ClientID );
objInit.Append( "', " );
objInit.Append( "MoveDownID:'" );
objInit.Append( this.moveDown.ClientID );
objInit.Append( "' }" );
//script.RegisterArrayDeclaration( "MetaBuilders_DualLists", objInit.ToString() );
ScriptManager.RegisterArrayDeclaration(Page, "MetaBuilders_DualLists", objInit.ToString());
}
}


Although I would probably focus on rebuilding the control for .net3.5 and follow a full ajax pattern implimenting "ScriptControl" and making use of the great new features.

John.