views:

27

answers:

1

I have to pass a string value from the server side page (.aspx.cs) to a function in .JS page. I need to call the function in JS page from server side page along with string as a parameter.

Can anyone please help me by providing samples or ideas to solve this problem?

A: 

If you want to call a JS method with a server-side variable, you can do something like this:

Page.ClientScript.RegisterStartupScript("SomeKey", "functionToCall('" + stringValueOnServer + "');", true);

This renders functionToCall('value'); so that the proper call happens, but functionToCall must be defined before this. Basically, have the script pretty high up in the page.

Brian
But the function used to call or pass the value to the .JS page is not in the page load....Can i use the "Page.ClientScript.RegisterStartupScript" for the functions which is not in the PAGE LOAD????? I tried but its not working.....UR THOUGHTS
This can be called on the server-side at any point, PreRender works too, or Init. I'm not sure what you mean by that; the Page property, has a ClientScript property, and the RegisterStartupScript method is used to register JavaScript code within the page at runtime.... could you clarify your question?
Brian