Page view counter

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
    • Loading...
    • kagome
    • Joined on 03-01-2007, 12:03 PM
    • Posts 123
    • Points 51

    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
    • Loading...
    • ecbruck
    • Joined on 12-30-2005, 7:39 PM
    • Des Moines, IA
    • Posts 9,159
    • Points 85,497
    • Moderator
      TrustedFriends-MVPs

    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
    • Loading...
    • codenenterp
    • Joined on 08-25-2008, 8:58 PM
    • Boise,Id
    • Posts 234
    • Points 1,059

    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
    • Loading...
    • kagome
    • Joined on 03-01-2007, 12:03 PM
    • Posts 123
    • Points 51

    thank you!

Page 1 of 1 (4 items)