FormView Error Handling

H

Howard

I use FormView and ObjectDataSource to take user inputs
in adduser.aspx page i have
<asp:ObjectDataSource ID="ds1" runat="server" TypeName="datapage"
InsertMethod="addstudent">

and in my app_code foler i have a method that looks like
public static void addstudent(...)
{
try
{
//do sql queries
catch(Exception e)
{
//return error message
}
}

this works fine when the inputs get inserted to the database, i call the
event OnItemInserted
My questions is how would i get the error message back to the aspx page?

Thanks,
Howard
 
B

Brock Allen

Handle the ObjectDataSource's Inserted event and check the EventArgs Exception
property. If this is non-null then you can "handle" the exception by setting
the EventArgs' ExcaptionHandled = true;
 
H

Howard

I still can't get it to work, tried everything

protected void ObjectDataSource1_Inserted(object sender,
ObjectDataSourceStatusEventArgs e)
{
if (e.Exception != null)
label1.message = "ERROR!";
}


In the business object i put
try
{
throw new Exception("test");
catch (Exception e)
{
}


e.Exception is always null, what did I do wrong. How come the exception is
not being passed to the Inserted event?
 
H

Howard

I still can't get it to work, tried everything

protected void ObjectDataSource1_Inserted(object sender,
ObjectDataSourceStatusEventArgs e)
{
if (e.Exception != null)
label1.message = "ERROR!";
}


In the business object i put
try
{
throw new Exception("test");
catch (Exception e)
{
}


e.Exception is always null, what did I do wrong. How come the exception is
not being passed to the Inserted event?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,179
Messages
2,570,956
Members
47,509
Latest member
Jack116

Latest Threads

Top