Formview and Sql Error Trapping and Page Validation...

  • Thread starter Thread starter Larry Bud
  • Start date Start date
L

Larry Bud

Got a Formview, and on the datasource "inserted" call, I check to see
if there was a SQL exception (such as a unique key failure). I then
handle the exception, displaying an error in a label. However, the
formview reverts back to readonly mode. How do I keep it in Insert
mode so the user can fix there data entry mistake?
 
Handle FormView's ItemInserted event instead and set KeepInInsertMode of the
passed FormViewInsertedEventArgs to true:

protected void MyFormView_ItemInserted(object sender,
FormViewInsertedEventArgs e)
{
if (e.Exception != null)
{
// display exception
lblException.Text = e.Exception.ToString();
e.KeepInInsertMode = true;
}
}

Regards
 
I forgot about setting exceptionhandled to true :

protected void MyFormView_ItemInserted(object sender,
FormViewInsertedEventArgs e)
{
if (e.Exception != null)
{
// display exception
lblException.Text = e.Exception.ToString();
e.KeepInInsertMode = true;
e.ExceptionHandled = true;
}
}

Now it should work like a charm.
 
Larry Bud said:
- Show quoted text -

Handle FormView's ItemInserted event instead and set KeepInInsertMode of the
passed FormViewInsertedEventArgs to true:

protected void MyFormView_ItemInserted(object sender,
FormViewInsertedEventArgs e)
{
   if (e.Exception != null)
   {
       // display exception
       lblException.Text = e.Exception.ToString();
       e.KeepInInsertMode = true;
   }    

}

Perfect, thanks.
 
Got a Formview, and on the datasource "inserted" call, I check to see
I forgot about setting exceptionhandled to true :

protected void MyFormView_ItemInserted(object sender,
FormViewInsertedEventArgs e)
{
   if (e.Exception != null)
   {
       // display exception
       lblException.Text = e.Exception.ToString();
       e.KeepInInsertMode = true;
       e.ExceptionHandled = true;
   }    

}

Now it should work like a charm.

So let me ask this: Is the formview or gridview the best place to do
error handling? I had the handing in the datasource object events,
in which case I had no access to the KeepInInsertMode.
 
Back
Top