JavaScript 和.net后台代码
如何在.aspx页面中的 <script> </script> 块中嵌套后台(.aspx.cs)的代码.
也就是:
<script>
后台(.aspx.cs)代码!??
</script>
如何实现这样的情况!!!!
[解决办法]
<script runat= "server ">
</script>
[解决办法]
在cs里定义字段 public String str;
在js里 <%=str%>
[解决办法]
<script runat= "server ">
</script>
[解决办法]
不知道楼主想要 实现什么功能?
[解决办法]
理想情况AJAX
[解决办法]
<script>
<%=scriptString%>
</script>
---------
.aspx.cs
protected string scriptString;
[解决办法]
<script runat= "server " language= "C# ">
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
label1.Text = "asdasdasdasdasdasdasdasd ";
}
}
private void Button1_OnClick(object sender, System.EventArgs e)
{
label1.Text = "asdasdasdasdasdasdasdasd ";
}
private void Button2_OnClick(object sender, System.EventArgs e)
{
label1.Text= " ";
}
</script>