C# 名称';ClientScript';在当前上下文中不存在
我有一个落后的javascript代码。它将显示一个javascript对话框 然而,它一直显示这个错误C# 名称';ClientScript';在当前上下文中不存在,c#,javascript,asp.net,C#,Javascript,Asp.net,我有一个落后的javascript代码。它将显示一个javascript对话框 然而,它一直显示这个错误 The name 'ClientScript' does not exist in the current context 此代码被放在母版页中。我在其他aspx文件中也使用了完全相同的代码,除此之外,它运行得很好 这是我的密码: protected void Button2_Click(object sender, EventArgs e) { string
The name 'ClientScript' does not exist in the current context
此代码被放在母版页中。我在其他aspx文件中也使用了完全相同的代码,除此之外,它运行得很好
这是我的密码:
protected void Button2_Click(object sender, EventArgs e)
{
string message = "Order Placed Successfully.";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("alert('");
sb.Append(message);
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString()); string script = "alert('abc');";
}
protectedvoid按钮2\u单击(对象发送者,事件参数e)
{
字符串消息=“订单已成功下达。”;
System.Text.StringBuilder sb=新的System.Text.StringBuilder();
某人加上(“”);
sb.Append(“window.onload=function(){”);
某人加上(“警告(”);
某人附加(信息);
某人加上(“)};”;
某人加上(“”);
ClientScript.RegisterClientScriptBlock(this.GetType(),“alert”,sb.ToString());string script=“alert('abc');”;
}
在母版页上尝试ScriptManager.RegisterStartupScript()
。注意,签名与Page.ClientScript.RegisterClientScriptBlock()
略有不同
- 会议文件
Page.ClientScript
而是看看它是否有区别。对于cs文件,示例是
ClientScript.RegisterClientScriptBlock(this.GetType(), "{some text for type}", "alert('{Text come to here}'); ", true);
对于母版页cs,示例为:
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "{some text for type}", "alert('{Text come to here}'); ", true);
Tnaks denize对我得到的“页面名称在当前上下文中不存在”的详细解释有什么想法吗?