Formview and Sql Error Trapping and Page Validation...

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?
 
M

Milosz Skalecki [MCAD]

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
 
M

Milosz Skalecki [MCAD]

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.
 
L

Larry Bud

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.
 
L

Larry Bud

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.
 

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

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top