You can emit client side javascript code to the browser in many different ways.
Arguably the best way to do this is to use the .RegisterStartupScript method of the Page object. For example, let's say that I have a variable, myServerVar in codebehind that I want accessible to a client side javascript function. First, you need to build the client side code that will be sent to the browser:
//this is in your codebehind
int myServerVar = 7;
string script = "<script language=javascript>var myClientVar = " + myVar.ToString() + ";</script>";
Now, you need to invoke the RegisterStartupScript method to send it to the browser:
Page.RegisterStartupScript("clientCode", script);
The net result is that this bit of js code will be emitted to the browser at the bottom of the page... right before the closing </form> tag. As you can see from the javascript, the client side variable, myClientVar, has been declared as a global variable, and as such, will be accessible in any function that you then choose to declare on the page.
If you need to control where on the page the js appears, then you can place an <asp:Label /> on the page, and then just assign the script value to the .Text property of the label. Most times, however, Page.RegisterStartupScript() is more than sufficient.
Good Luck.
-paul
The answer to getting answered -- faq855-2992