user1529419
user1529419

Reputation: 441

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

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

    }   

Upvotes: 20

Views: 41761

Answers (3)

denizemektup
denizemektup

Reputation: 85

For cs file the sample is;

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

for masterpage cs the sample is;

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

Upvotes: 8

Brian Mains
Brian Mains

Reputation: 50728

Try:

Page.ClientScript

instead to see if it makes a difference.

Upvotes: 52

Dennis Traub
Dennis Traub

Reputation: 51694

On the master page try ScriptManager.RegisterStartupScript() instead. Watch out, the signature slightly differs from Page.ClientScript.RegisterClientScriptBlock().

Upvotes: 3

Related Questions