Formview and Sql Error Trapping and Page Validation...

Formview and Sql Error Trapping and Page Validation...

am 25.01.2008 21:44:55 von 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?

RE: Formview and Sql Error Trapping and Page Validation...

am 27.01.2008 03:31:01 von mily242

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
--
Milosz


"Larry Bud" wrote:

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

RE: Formview and Sql Error Trapping and Page Validation...

am 27.01.2008 03:34:00 von mily242

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


"Milosz Skalecki [MCAD]" wrote:

> 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
> --
> Milosz
>
>
> "Larry Bud" wrote:
>
> > 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?
> >

Re: Formview and Sql Error Trapping and Page Validation...

am 27.01.2008 15:52:32 von Larry Bud

> "Larry Bud" wrote:
> > 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?- Hide quoted text -
>
> - Show quoted text -

On Jan 26, 9:31=A0pm, Milosz Skalecki [MCAD]
wrote:
> Handle FormView's ItemInserted event instead and set KeepInInsertMode of t=
he
> passed FormViewInsertedEventArgs to true:
>
> protected void MyFormView_ItemInserted(object sender,
> FormViewInsertedEventArgs e)
> {
> =A0 =A0if (e.Exception !=3D null)
> =A0 =A0{
> =A0 =A0 =A0 =A0// display exception
> =A0 =A0 =A0 =A0lblException.Text =3D e.Exception.ToString();
> =A0 =A0 =A0 =A0e.KeepInInsertMode =3D true;
> =A0 =A0} =A0 =A0
>
> }

Perfect, thanks.

Re: Formview and Sql Error Trapping and Page Validation...

am 28.01.2008 14:52:08 von 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?- Hide quoted text -=

>
On Jan 26, 9:34=A0pm, Milosz Skalecki [MCAD]
wrote:
> I forgot about setting exceptionhandled to true :
>
> protected void MyFormView_ItemInserted(object sender,
> FormViewInsertedEventArgs e)
> {
> =A0 =A0if (e.Exception !=3D null)
> =A0 =A0{
> =A0 =A0 =A0 =A0// display exception
> =A0 =A0 =A0 =A0lblException.Text =3D e.Exception.ToString();
> =A0 =A0 =A0 =A0e.KeepInInsertMode =3D true;
> =A0 =A0 =A0 =A0e.ExceptionHandled =3D true;
> =A0 =A0} =A0 =A0
>
> }
>
> 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.