Monday, March 26, 2012

Execute Javascript from Codebehind AFTER AsyncPostback

Hi all,

In my code, I'm trying to dynamically execute a javascript function from my codebehind after an ajax postback. I call RegisterStartupScript in my event handler, and this worked in the Atlas July CTP but is no longer working in Beta 2? I've tried both RegisterStartupScript and RegisterScriptBlock and neither executes my javascript. What is the proper way to do this now? Here is my function call

Page.ClientScript.RegisterClientScriptBlock(scriptString.getType, "loadScript", scriptString)

I would like to execute the script contained in scriptString from codebehind only after the async postback is made

Would appreciate any help!
-Steve

hello.
in this release you need to use the static registerXXX methods?of?the?ScriptManager?class?to?insert?jscript?code?from?a?partial?postback?request.

Hi,

I am using the ScriptManager class but my javascript still doesn't seem to be registering. Here is my code:


If CType(me.Master.FindControl("ScriptManager1"), ScriptManager).IsInAsyncPostBack = True then
ScriptManager.RegisterClientScriptBlock(Me, GetType(Page), "jscript", "var newcbid = " & checkbox.ClientID & ";", True)
End If

The javascript isn't getting registered... is this because I'm registering from a child page?


nevermind, found the problem. Used the updatepanel as the the Control parameter of the RegisterClientScriptBlock and it worked:


ScriptManager.RegisterClientScriptBlock(UpdatePanel1, GetType(UpdatePanel), "jscript", "var newcbid=" & checkbox.ClientID & ";", True)

No comments:

Post a Comment