Valerie Meunier

Valerie Meunier

  • NA
  • 693
  • 81.3k

errors with static method

Aug 2 2021 2:15 PM

Hi,

this code for catching sql general errors in a website project works good.

protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {
        if (e.Exception == null)
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('ok');", true);
        }
        else
        {
          ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('Error!');", true);
           e.ExceptionHandled = true;
        }

Now, I want to put this code in a static method (in App_Code) in order to reuse it on several places in my project. But i get two errors:

using System;
using System.Web;
public class Class1
{
    public static void Check()
    {
        if (e.Exception == null)
        {
            
            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('ok');", true);
        }
        else
        {
        ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('Error!');", true);
          
            e.ExceptionHandled = true;
        }
    }
}

The first error is: 'e' doesn't exist in current context.

The 2nd error: 'ClientScript doesn't exist in current context (i also tried with Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('ok');", true), same error: 'Page' doesn't exist ...

Thanks for help.

V
       


Answers (8)