Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

    }   
like image 738
user1529419 Avatar asked Aug 04 '12 11:08

user1529419


3 Answers

Try:

Page.ClientScript

instead to see if it makes a difference.

like image 167
Brian Mains Avatar answered Oct 19 '22 03:10

Brian Mains


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);
like image 21
denizemektup Avatar answered Oct 19 '22 03:10

denizemektup


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

  • Documentation of the ScriptManager Class
like image 3
Dennis Traub Avatar answered Oct 19 '22 04:10

Dennis Traub