Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery with update panel

i have a problem while using jquery context menu and update panels. i am writing the javascript of the context menu in the RenderBeginTag of a Customtextbox control using htmlTextWriter. everything works fine, i can right click on every textbox and the menu appears.
but when i triger a partial postback using an asp.net updatepanel, the menu won't be displayed. it seems that the binding between jquery and the html is lost when partial post back happened.
is there any better way to place dynamic javascript code other than in RenderBeginTag ? how can i solve this issue?

like image 518
scatman Avatar asked May 31 '26 13:05

scatman


2 Answers

You're right, the updatepanel will remove your javascript bindings.

In your updatepanel postback, re-register the javascript in question.

Something like:

ClientScriptManager cs = Page.ClientScript;
cs.RegisterStartupScript(typeof(Page), "ReApplyJavascript", "<script type=text/JavaScript>YourJavascriptInitMethod();</script>", false);

If that doesn't work. You may need to use:

   ScriptManager.RegisterStartupScript(Page, typeof(Page), "ReApplyJavascript", "<script type=text/JavaScript>YourJavascriptInitMethod();</script>", false);
like image 185
Brandon Boone Avatar answered Jun 02 '26 01:06

Brandon Boone


You need to reinitialize the menou after UpdatePanel Update.

<script type="text/javascript"> 
var prm = Sys.WebForms.PageRequestManager.getInstance();    
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);

function InitializeRequest(sender, args) {      
}

function EndRequest(sender, args) {
     // Here initialize the menou
}
</script>
like image 33
Aristos Avatar answered Jun 02 '26 03:06

Aristos