"ClientScript"这个名称在当前上下文中不存在

use*_*419 18 javascript c# asp.net

我有一个后置码javascript.它是显示一个JavaScript对话框.

但是,它会继续显示此错误

The name 'ClientScript' does not exist in the current context
Run Code Online (Sandbox Code Playgroud)

此代码放在母版页中.我也在其他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');";

    }   
Run Code Online (Sandbox Code Playgroud)

Bri*_*ins 50

尝试:

Page.ClientScript
Run Code Online (Sandbox Code Playgroud)

相反,看它是否有所作为.


den*_*tup 8

对于cs文件,样本是;

ClientScript.RegisterClientScriptBlock(this.GetType(), "{some text for type}", "alert('{Text come to here}'); ", true);
Run Code Online (Sandbox Code Playgroud)

对于主页cs,样本是;

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "{some text for type}", "alert('{Text come to here}'); ", true);
Run Code Online (Sandbox Code Playgroud)