How to call a javascript function from a server-side function

Hi. I'd like to know if it's possible to call a javascript function from within a server-side function.

I know it's possible to associate a javascript function with a control event but I'd like to call it from within an function.


Samir Zattar

0 samirzattar 5/29/2007 7:05:26 PM


There are several ways to do it, all through the Page.ClientScript property.  You can write a script through RegisterClientScriptBlock or RegisterStartupScript, or if you have a script file you can write a reference to that file.


"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
0 bmains 5/29/2007 7:21:17 PM


as server-side code runs before the client-side code (per request), this is usually achieved so that you generate a js call on the server-side code, and by the time page gets rendered in the browser, the generated script is executed.

The world's simplest example to demonstrate this is to call this on Button's click:


0 joteke 5/29/2007 7:23:57 PM

Thanks for the reply, but doing what you described would only work with a post-back, right?
I'd like to call the function using AJAX functionality, with no post-backs.

Samir Zattar

0 samirzattar 5/29/2007 7:33:49 PM

In that case, you could register the call with ScriptManager. here's an example


0 joteke 5/29/2007 8:02:43 PM

That will do it! Thanks

0 samirzattar 5/30/2007 3:45:48 PM

(Thread closed)