Formview and Sql Error Trapping and Page Validation...

Discussion in 'ASP .Net' started by Larry Bud, Jan 25, 2008.

  1. Larry Bud

    Larry Bud Guest

    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, Jan 25, 2008
    #1
    1. Advertising

  2. 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?
    >
     
    Milosz Skalecki [MCAD], Jan 27, 2008
    #2
    1. Advertising

  3. 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?
    > >
     
    Milosz Skalecki [MCAD], Jan 27, 2008
    #3
  4. Larry Bud

    Larry Bud Guest

    > "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 pm, 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;
    >    }    
    >
    > }


    Perfect, thanks.
     
    Larry Bud, Jan 27, 2008
    #4
  5. Larry Bud

    Larry Bud Guest

    > > > 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 pm, Milosz Skalecki [MCAD] <>
    wrote:
    > 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.
     
    Larry Bud, Jan 28, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    Trapping a particular SQL Error Code

    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Jul 18, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    3,715
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
    Jul 18, 2005
  2. =?Utf-8?B?UGF1bA==?=

    Error Trapping and Error Line Number

    =?Utf-8?B?UGF1bA==?=, Oct 26, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    487
    Hans Kesting
    Oct 27, 2005
  3. Ed Jay
    Replies:
    14
    Views:
    748
    Ed Jay
    Nov 15, 2005
  4. Chris

    Formview within Formview

    Chris, May 19, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    585
    Chris
    May 19, 2007
  5. David Thielen

    FormView/Repeater/ Eval(FormView data)

    David Thielen, Jun 16, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    714
    David Thielen
    Jun 16, 2006
Loading...

Share This Page