Formview and Sql Error Trapping and Page Validation...

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?
Larry Bud [ Fr, 25 Januar 2008 21:44 ] [ ID #1916068 ]

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

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?
>
mily242 [ So, 27 Januar 2008 03:31 ] [ ID #1917151 ]

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

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?
> >
mily242 [ So, 27 Januar 2008 03:34 ] [ ID #1917152 ]

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

> "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] <mily... [at] DONTLIKESPAMwp.pl>
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.
Larry Bud [ So, 27 Januar 2008 15:52 ] [ ID #1917165 ]

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

> > > 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] <mily... [at] DONTLIKESPAMwp.pl>
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.
Larry Bud [ Mo, 28 Januar 2008 14:52 ] [ ID #1917875 ]
Microsoft » microsoft.public.dotnet.framework.aspnet » Formview and Sql Error Trapping and Page Validation...

Vorheriges Thema: DllImport on framework 1.1, in IIS 6 (Windows Vista)
Nächstes Thema: Windows XP Pro, IIS and .NET 3.0/3.5