开发者

How do you get client-side script to execute on an ASP.NET postback? (from an UpdatePanel)

开发者 https://www.devze.com 2023-01-07 03:12 出处:网络
Basically I want to get some javascript to be sent back开发者_JAVA百科 to the client and executed from a postback inside an UpdatePanel.Furthermore this is inside of a reusable WebControl.

Basically I want to get some javascript to be sent back开发者_JAVA百科 to the client and executed from a postback inside an UpdatePanel. Furthermore this is inside of a reusable WebControl.

I've tried this.Page.ClientScript.RegisterStartupScript and this.Page.ClientScript.RegisterClientScriptBlock but Firebug shows that those scripts aren't sent back in the postback's response.

I also tried straight up writing a <script> tag inside the control's main div in the Render method, which does get sent back but isn't executed.

I got a hacky solution working, but ideally looking for a cleaner solution. The hack is to add a 1x1 pixel img with width/height set to 0 and use that for an onload event to execute the script and that works, but it seems like there has to be a cleaner way to do this.


If I understand correct you look for the endRequest event - to avoid the onload of your image. With this code you get the event of your panel update on javascript side.

var prm = Sys.WebForms.PageRequestManager.getInstance();    
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);

function InitializeRequest(sender, args) {      
}

function EndRequest(sender, args) {
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号