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
Valerie MeunierPosted Aug 5, 2021, 4:34 PM
Valerie MeunierPosted Aug 5, 2021, 4:18 PM
Sachin SinghPosted Aug 5, 2021, 9:39 AM
Valerie MeunierPosted Aug 5, 2021, 9:22 AM
Sachin SinghPosted Aug 4, 2021, 2:34 PM
Valerie MeunierPosted Aug 4, 2021, 1:22 PM
Valerie MeunierPosted Aug 3, 2021, 9:07 AM
Sachin SinghPosted Aug 2, 2021, 3:00 PM