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 serve开发者_如何学Pythonr 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.
精彩评论