I would like to understand how I can run client-side javascript after an update panel has finished updating given various constraints. My development scenario is non-trivial however, I would like to illustrate the problem by describing a simpler case.
I have a user-control containing an update panel which contains a button and a table. When the user clicks the button an async postback occurs, the table's rows will be changed and the altered table will be returned and rendered on the client.
I would like to run a a script to perform some custom formatting on the table. Lets say for now I want to zebra stripe the table. (Actual requirements are more complex).
I thought I would simply be able to emit script as part of the user controls output and whenever an update occurs the table markup and the script would be handled on the client and all w开发者_Go百科ould be fine, but that technique does not work.
I've seen other posts that reference ClientScriptManager, but that doesn't seem to be available inside my user control. Should I add a ScriptManagerProxy?
So what's the best way to proceed, given the constraints.
- The update panel is inside a user control.
- There could be more than one instance of the user control on the page.
Looks like I need to
- Generate a unique update script for each instance of the user-control.
- Find a way to "register" each script
- Find a way to ask for the script to be run when the corresponding updatePanel has finished updating.
I seem to have seen many examples which are close but none which match my circumstances; I can't quite figure out how to get it all to hang together.
you will have to write EndRequestHandler for it. It is a very common problem,Javascript,Jquery stops working after async postback from update panel. In this link i have explained how to do it. http://codethatworkedforme.blogspot.com/2011/08/having-issues-with-update-panel.html
For a unique update script for each instance of the user-control, you can try this
function yourFunctionName<%= ClientID %>() { //do something }
You can invoke the client script in button client envent handler on server side using this
protected void btn_click(object sende, EventArgs e) { ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), string.Format("yourFunctionName{0}();", ClientID), true); }
精彩评论