Forum Moderators: open

Message Too Old, No Replies

Over - eager Validation Control

         

txbakers

5:36 pm on May 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have an input box with a button on the same screen as an editable datagrid. I put a validation on the input box so it wasn't blank. That worked and displays a nice message.

However, when I click on the Edit button of the dataGrid, make my changes and click the Enter button of the datagrid, the validation still kicks in and won't let me submit.

I did a work around by putting the validation in the codeBehind instead of in a control.

Is that the best solution?

I really want a personal guru.....8(

TheNige

8:33 pm on May 13, 2005 (gmt 0)

10+ Year Member



you need to set the edit button of the datagrid to: CausesValidation=False

txbakers

8:42 pm on May 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's what I thought too, but there is no CausesValidation property on the DataGrid buttons.

TheNige

9:03 pm on May 13, 2005 (gmt 0)

10+ Year Member



Try using template columns and add your own buttons where you can set that property.

Xoc

7:08 pm on May 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Expanding on what TheNige said, at the bottom of the DataGrid column configuration dialog, there is a hyperlink button that will turn the column into a Template column. Then you can right click on the DataGrid and edit the template for that column. It will give you real controls that you can click on and set properties on.

You might also want to set all the Validation controls on the page to have EnableClientScript turned off. This will cause all validation to be done server side.

txbakers

7:58 pm on May 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks X - I appreciate all the help.

One question about the EnableClientScript = false idea.

The reason .NET put the validation in both client and server was for older browsers that couldn't do client side. The prefered method is client side.

Client side is faster, but is there much of a loss doing it only server side?

mattglet

3:29 am on May 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Doing it only server side will be more expensive, as it will cause unnecessary postback calls. If the errors can be taken care of via client side validation before any server side post needs to be made, it's less work for the server.

Xoc

11:38 am on May 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Validation is always done server side. It may be done client side in addition. The user can turn off JavaScript, so server side validation must be done by .NET.

Although client side validation gives a "more interactive feel", any time you have extensive JavaScript (and client side validation is fairly extensive), you have the risk that the client side code won't work in some browser.

Regardless of whether you choose client or server side, make sure that all of the validation controls on the page have the EnableClientScript property set the same way. It is a weird user experience to fix what they see as all the errors on their form as shown by client side validation, then have the server side validation rules kick in and give them a whole new batch of errors.

Personally, I don't find the benefits of client side validation to outweigh the risk, and in many cases the user can't tell the difference.

mattglet

12:23 pm on May 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Xoc-

I have to partially disagree with you. (First I'll make my former point clear: Server-side (SS) validation is a must, client-side (CS) is a bonus).

If you have the opportunity to perform CS validation, you absolutely should do it, if not for the "interactive" factor, then to at least save server resources.

I frankly don't buy the "might not work in some browsers" bit. If you develop it, you always make sure it works in all browsers (or whatever you deem is necessary; everyone has their limits). Just because the time won't be taken to browser-check your code, doesn't mean you shouldn't do it. JavaScript is actually quite flexible across browsers, and you should hardly every run into any problems with compatibility (especially if you're just performing form validation).

If you have 1 million visitors per month to a registration page on your site, and 10% have an error that could have been caught via CS validation, that's 100,000 form posts that could have been saved, and those server resources not used.

While I agree it's personal preference as to your choice for CS validation, I think it should be highly considered.

txbakers

2:18 pm on May 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



the simple fact remains, that although most people don't know HOW to turn off javascript, enough do to bypass CS validation.

I always agreee that CS validation is the first choice though to make it faster for the user. There is no need for a trip to the server only to find out a phone number was missing.

I think my personal issue above will be solved by using a Template inside the DG.