Sunday, August 2, 2009

Problem lose the drag and drop capability from update panel then call jQuery code from ASP.NET Server-Side

I am using the jQuery for the drag and drop functionality. When refresh the contents of the update panel and hence the HTML controls lose the drag and drop capability.

I'm using the .net ScriptManager.RegisterClientScriptBlock method to register my script , so that all items from the HTML control can be "Draggables".

ScriptManager.RegisterClientScriptBlock(this,this.GetType(),"script", "DragAndDrop();", true);

The catch is that using ClientScript.RegisterClientScriptBlock simply won’t render your scripts when the request is coming from an AsyncPostbackTrigger of an UpdatePanel. In this case you’ll need to call


ScriptManager.RegisterClientScriptBlock.

Registers a client script block with the ScriptManager control for use with a control that is inside an UpdatePanel control, and then adds the script block to the page.

RegisterClientScriptBlock(Control, Type, String, String, Boolean)

No comments: