2012年3月10日土曜日

Run a javascript function after UpdatePanel.Update()

Hi,

you could use the RegisterStartupScript method of the ScriptManager to programmatically inject the script to load after a partial postback.


Damnit, I'm still running the pre-release version of the binaries. Any other way?

Upgrade. :-)

Really, any particular reason you're still on a prerelease build? I don't remember when those methods got introduced on the ScriptManager, but they might be in your build too.


Well, intellisense says no. And upgrading is in the pipe; there are more pressing issues that need to be taken care of. The build I'm using is stable enough to put upgrading on a back burner for the near term...
Like Steve Marx said, please upgrade to the RTM version. You will save a lot of time - do not assume the framework version you are working with is stable.

Hi,

here's my scenario:

A button inside an UpdatePanel is clicked, some server side code runs, and I want to run a JS function after the server side processing ends. The JS function to run is dependent on the server side processing and its result.
In the OnClick event handler of the button, as last line, I have:

ScriptManager.RegisterStartupScript(this,this.GetType(),"temp","<script language='javascript'>alert('x');</script>",false);

However, no alert is displayed at client side. What am I missing?

Thanks.

PS: all this happens in an ascx control


Hi,

You should call the method in this way:

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp", "<script type='text/javascript'>alert('x');</script>", false);

The problem could be the fact that you are using this instead of this.Page. Also insteadlanguage='javascript' you can usetype='text/javascript'.

Hope it helps...


Hello,

Did this fix your problem? I'm having a similar issue where my script runs on page load, but subsequent partial renders do not fire the script. Please let us know if this solution worked for you or if you had to tweak it more.

Thanks,

Brendan


See for more details...

http://ajax.asp.net/docs/mref/O_T_System_Web_UI_ScriptManager_RegisterStartupScript.aspx


If your issue is resolved, Please mark the answer

It will help for others..


Thanks, got it to work by moving my js into a true function (instead of just inline) and calling it all via:

ScriptManager.RegisterStartupScript(this,typeof(Sections),"Initialize","initialize();",true);


Yes

ciprian_kis:

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp", "<script type='text/javascript'>alert('x');</script>", false);

If we want to execute JS function during ajax call

write your script in page load

 ScriptManager.RegisterStartupScript(this.updatePaneLid,this.GetType(),"Show_Font","showFont();",true);
---

Hope this helps

0 件のコメント:

コメントを投稿