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?
views:
40answers:
2
A:
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);
Brandon Boone
2010-08-04 13:49:11
i have tried them both, and they did not work. i am putting the scripts in the RenderBeginTag of the costum control. is this the right place?
scatman
2010-08-04 14:02:59
Unfortunatly, I'm not that familiar with custom controls. I've typically used this code on the code behind of the Page not in the control. Does RenderBeginTag fire when your Update Panel performs a partial postback?
Brandon Boone
2010-08-04 14:36:59
Actually, I wouldn't register any of the scripts with RenderBeingTag. I would register them all with one of the RegisterStartUpScript Methods every time the control is rendered.
Brandon Boone
2010-08-04 14:45:19
+1
A:
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>
Aristos
2010-08-04 16:09:41