一般来说是没有什么办法的。
不过你可以在页面上加载一个HTML控件。一般用hidden控件,假设ID为hidden1.
再把它作为服务器端控件运行。然后在你的CS文件中把变量保存到hidden1控件的value中。
这样你在Javascript中用document.all["hidden1"].value就行了。
不过你可以在页面上加载一个HTML控件。一般用hidden控件,假设ID为hidden1.
再把它作为服务器端控件运行。然后在你的CS文件中把变量保存到hidden1控件的value中。
这样你在Javascript中用document.all["hidden1"].value就行了。
是在客户端(脚本)和服务器端(CS文件中吧)都可以调用的。
<INPUT type="hidden" id="h1" runat="server">---改成服务端控件
<script language="javascript">
alert(document.WebForm1.h1.value);
</script>
在cs中:
private void Page_Load(object sender, System.EventArgs e)
{
string jj="hello";
h1.Value=jj;
}
我是在想在JAVASCRIPT中调用文件中定义的变量啊
如:
form1.cs
string[] arr = new string[5];
string[0] = "hello";
那么我在form1.aspx中写一段JAVASCRIPT代码取得这个字符串数组中的值
例如
public void SetWebService()
{
//设定WEB服务器
string usl="http://"+this.Request.ServerVariables["SERVER_NAME"].ToString()+this.ResolveUrl("GetMessage.asmx")+"?WSDL";
this.Response.Write("<script>");
this.Response.Write("function init(){");
this.Response.Write("myWebService.useService(\""+usl+"\",\"service1\");");
this.Response.Write("Getd();");
this.Response.Write("}");
this.Response.Write("</script>");
}