Details View ItemUpdating e.cancel

Last post 01-18-2007 10:29 AM by Skip_Frog. 9 replies.

Sort Posts:

  • Details View ItemUpdating e.cancel

    01-12-2007, 5:23 PM
    • Member
      52 point Member
    • Skip_Frog
    • Member since 12-20-2006, 12:30 PM
    • Posts 171

    Hi All,

    When I use the e.cancel=true in the item updating event it cancels the update which I want. But it also returns the original values which I do not want. So how do I keep the new values?

    Thanks

  • Re: Details View ItemUpdating e.cancel

    01-13-2007, 5:53 AM
    • All-Star
      17,061 point All-Star
    • Dave Sussman
    • Member since 06-17-2002, 11:53 AM
    • UK
    • Posts 2,359
    • ASPInsiders
      TrustedFriends-MVPs

    When you cancel the Updating event, the DetailsView is left in edit mode and the values you entered are not changed. Is this not the behaviour you are seeing?

     If you want to manipulate the values in the DetailsView you can iterate through the Rows collection (one row for each field displayed), and then the Cells collection (two cells: the header, the value).

    Dave

  • Re: Details View ItemUpdating e.cancel

    01-16-2007, 9:20 AM
    • Member
      52 point Member
    • Skip_Frog
    • Member since 12-20-2006, 12:30 PM
    • Posts 171

    No when I cancel the updating event, the Details view is indeed left in edit but the original values are returned.

    Thanks

  • Re: Details View ItemUpdating e.cancel

    01-16-2007, 9:24 AM
    • All-Star
      17,061 point All-Star
    • Dave Sussman
    • Member since 06-17-2002, 11:53 AM
    • UK
    • Posts 2,359
    • ASPInsiders
      TrustedFriends-MVPs

    Do you have any other binding code that would be refreshing these values? When I created a test page with just a SqlDataSource and FormView control (no code) it worked for me.

    Dave

  • Re: Details View ItemUpdating e.cancel

    01-16-2007, 10:36 AM
    • Member
      52 point Member
    • Skip_Frog
    • Member since 12-20-2006, 12:30 PM
    • Posts 171

    Yeah I started removing code and found the commented out lines below cause this behavior. Running it this way (commented out) everything is good.. Any thoughts on why this would be happenning?

    If

    Check_CA < 4 Then

    CA = e.NewValues(

    "Corrective_Action")

    If Len(CA) < 20 Then

    'Me.DetailsView1.Fields(12).HeaderText = "C/A is required"

    'Me.DetailsView1.Fields(12).HeaderStyle.ForeColor = Drawing.Color.Red

    e.Cancel =

    True

    'Exit Sub

    End If

    Else

    'Me.DetailsView1.Fields(12).HeaderText = "Corrective Action"

    'Me.DetailsView1.Fields(12).HeaderStyle.ForeColor = Drawing.Color.Black

    End If

     

     Thanks

     

  • Re: Details View ItemUpdating e.cancel

    01-16-2007, 10:44 AM
    • All-Star
      17,061 point All-Star
    • Dave Sussman
    • Member since 06-17-2002, 11:53 AM
    • UK
    • Posts 2,359
    • ASPInsiders
      TrustedFriends-MVPs

    That's very odd, I've no idea why it should cause a problem. Is it both lines of code that cause the issue, or just setting the HeaderText?

    d

  • Re: Details View ItemUpdating e.cancel

    01-16-2007, 10:44 AM
    • Member
      52 point Member
    • Skip_Frog
    • Member since 12-20-2006, 12:30 PM
    • Posts 171

    It looks like setting the header text is the culprit. Any thoughts.

    Thanks

  • Re: Details View ItemUpdating e.cancel

    01-17-2007, 4:19 AM
    • All-Star
      17,061 point All-Star
    • Dave Sussman
    • Member since 06-17-2002, 11:53 AM
    • UK
    • Posts 2,359
    • ASPInsiders
      TrustedFriends-MVPs

    You're right, what a strange situation. I would report this as a bug at the MSDN Feedback centre (https://connect.microsoft.com/feedback/). Anything reported here gets through to the development team. If this is a blocking issue you can report it to Product Support and investigation will be escalated and maybe a patch would be created.

    In the mean time, as a workaround, you can manually repopulate the fields from the NewValues collection; it's not a great solution, but would allow you to keep working.

    Alternatively, don't set the title text, but maybe have a label outside of the DetailsView that you update with error/warning messages. Or you could tempalte all of your fields and add a field alongside, to the right.

    Dave

  • Re: Details View ItemUpdating e.cancel

    01-17-2007, 1:27 PM
    Answer
    • All-Star
      17,061 point All-Star
    • Dave Sussman
    • Member since 06-17-2002, 11:53 AM
    • UK
    • Posts 2,359
    • ASPInsiders
      TrustedFriends-MVPs

    OK, straight from the ASP.NET development team comes this reply: 

    Setting certain properties forces the DetailsView (or the GridView or the FormView) to re-databind to reflect the new values.  HeaderText on the fields is one of those properties.  If the control didn’t rebind, setting the HeaderText to anything (even “Wibble”) wouldn’t do anything until you call DataBind explicitly.  Since our goal with the new data controls was to not require the user to call DataBind explicitly in all mainline scenarios, we need to call DataBind if properties that affect the rendering or control tree are changed.

    This makes sense and fits with the control.

    So the best approach would be to have your messages outside of the control, or as templated columns.

    Dave

  • Re: Details View ItemUpdating e.cancel

    01-18-2007, 10:29 AM
    • Member
      52 point Member
    • Skip_Frog
    • Member since 12-20-2006, 12:30 PM
    • Posts 171

    Thanks for your help. I have taken your advice and placed a label outside of the control and all is fine. 

     

Page 1 of 1 (10 items)