20

I have a behindcode javascript. it is to show a javascript dialog box.

however, it keep show this error

The name 'ClientScript' does not exist in the current context

This code was put inside masterpage. I had also use the exactly same code at other aspx file, and it work out fine apart from this..

here is my code:

   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');";

    }   
4

3 回答 3

52

尝试:

Page.ClientScript

而是看看它是否有所作为。

于 2012-08-04T11:42:03.650 回答
8

对于cs文件,示例是;

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

对于masterpage cs,示例是;

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "{some text for type}", "alert('{Text come to here}'); ", true);
于 2014-02-21T14:58:01.670 回答
3

在母版页上尝试ScriptManager.RegisterStartupScript()。请注意,签名与 . 略有不同Page.ClientScript.RegisterClientScriptBlock()

于 2012-08-04T11:40:48.857 回答