Server variables and the .js file. Is it possible?
is it possible to invoke server variables in the external .js file ?
[Edit] OK, I resolve开发者_开发问答d the problem, thank for Your help ! :)
No, internal JS you can
<script>
var i = <%= ServerSideVar %>
</script>
When you say, "invoke a server variable" do you mean you want to change the value of a variable or did you mean to say, "invoke a function on the server?"
This can be done using an ajax call back to the server (assuming you are trying to avoid a postback).
Use Page.ClientScript.RegisterStartupScript() or Page.ClientScript.RegisterClientScriptBlock() to register the value of your server variables to JavaScript variables and then you can call them from the external .js file
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "variables", String.Format("var var1 = {1}; var var2 = {2};", someVariable1, someVariable2));
精彩评论