stop the update query from executing if my code-behind validation fails.

Last post 08-28-2008 3:08 PM by kagome. 3 replies.

Sort Posts:

  • stop the update query from executing if my code-behind validation fails.

    08-28-2008, 2:33 PM
    • Member
      52 point Member
    • kagome
    • Member since 03-01-2007, 12:03 PM
    • Posts 127

    Hello All,

    I would like to validate a textbox in a detailview before it updates the database.  I have a code-behind validation that if its true; i  want the update query(using query builder) not started and have the user fix the problem.  I can not use a validation group; since i only have 1 hyperlink button; which is the update query itself. I also have other validations on the page; but i only what this textbox valided if the checkbox is not selected. Therefore, i am using a code-behind validation.

    for example:

    I have a textbox that is empty and i need the user to fill it in.  I want my code-behind to take proirity before the updated query is executed. 

     Any ideas of how i can stop the update query from executing if my code-behind validation fails.

    Thanks

    Kagome

  • Re: stop the update query from executing if my code-behind validation fails.

    08-28-2008, 2:56 PM
    Answer
    • All-Star
      86,764 point All-Star
    • ecbruck
    • Member since 12-30-2005, 7:39 PM
    • Des Moines, IA
    • Posts 9,209
    • Moderator

    Within the DetailsView.ItemUpdating event handler do your validation. If it fails, then simply set the Cancel property of the DetailsViewUpdateEventArgs class to True.

    Thanks, Ed

    Microsoft MVP - ASP/ASP.NET

  • Re: stop the update query from executing if my code-behind validation fails.

    08-28-2008, 2:57 PM
    • Participant
      1,059 point Participant
    • codenenterp
    • Member since 08-25-2008, 8:58 PM
    • Boise,Id
    • Posts 234

    Ok you have two options.  Option one is make the hyper link a asp:Linkbutton that way you have an onclick event to do server side validation, and determine if you want to run the query.  Option number is to do some javascript validation in the onclick event of the button client side.

    Solutions Architect
    Coden Enterprises
    http://www.codenenterprises.com/iblog
  • Re: stop the update query from executing if my code-behind validation fails.

    08-28-2008, 3:08 PM
    • Member
      52 point Member
    • kagome
    • Member since 03-01-2007, 12:03 PM
    • Posts 127

    thank you!

Page 1 of 1 (4 items)