Tutorial :How to pass a value from the serverside page to a function in .JS file in asp.net


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?


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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »