开发者

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

开发者 https://www.devze.com 2023-01-09 19:57 出处:网络
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 fromserver side page along with string as a para

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消