A C

A C

  • NA
  • 5
  • 0

How to : Generic error handling function. Passing GridViewUpdatedEventArgs, FormViewInsertedEventArgs and other as EventArgs

Sep 8 2010 9:15 PM

Hi,

This is regarding an ASP.NET project coded in C# using the .NET 3.5 framework.

I want to build a generic error handling function for handling inseted, updated, deleted events from formview, gridview and detail view. I am still a bit new to C# so I have encoutered a simple problem that I cannot resolve and cannot find an answer while searching google.

Right now I handle error with validator for generic validation but I need to catch BLL error.

I have different event handler for the different type of event :

     protected void FormView_AjoutCompte_ItemInserted(object sender, FormViewInsertedEventArgs e)
{
if (e.Exception != null)
{
Afficher_Erreur(e.Exception);
e.ExceptionHandled = true;
}
}

protected void GridView_ListeUtilisateurs_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
if (e.Exception != null)
{
Afficher_Erreur(e.Exception);
e.ExceptionHandled = true;
}
}

protected void GridView_ListeUtilisateurs_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
if (e.Exception != null)
{
Afficher_Erreur(e.Exception);
e.ExceptionHandled = true;
}
}

I want to create a generic function that will handle them all, a function such as :

  protected void HandleError(object sender, EventArgs e)
{
if (e.Exception != null)
{
Afficher_Erreur(e.Exception);
e.ExceptionHandled = true;
}
}

But I get the error  : 

Error	1	'System.EventArgs' does not contain a definition for 'Exception' and no extension method 'Exception' accepting a first argument of type 'System.EventArgs' could be found (are you missing a using directive or an assembly reference?)	\\SKYNET\wwwroot\Budget\UtilisateursEtComptes\Comptes.aspx.cs	109	14	\\SKYNET\wwwroot\Budget\

How can I do this ?


Answers (5)