To validate or not to validate

Hey people!

Here is my situation - I've created a dynamic data website with one table.
The fields of this table are mostly varchar() not NULL, and all fields are defined with default value.
When trying to insert new row with empty values I get required validation on all fields.
What would be the best way to enable this validation only on some of these fields, while using default
values for the others?
For example empty string for varchar or 0 for int, etc

12/16/2008 2:00:26 PM 1365 articles. 0 followers. Follow

11 Replies

Similar Articles

[PageSpeed] 6

no in this case it will be add

 what error its return when u add.

.Net Developer

Web Site Design and Web Site Development Company, Madurai, Tamil Nadu, India.
12/16/2008 2:10:19 PM


Yes you need to validate all your textboxes etc, unless you have told the database to accept "NULL's". The insert will not product an error then. 

Its a security feature as well as looking better.

This link explains how to validate your page.

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. Check out
12/16/2008 2:11:58 PM
Ok. In other words what I want is to remove required validation from some of the fields and substitute the null
with another default value before it is actually inserted/updated in the database.
What is the right way to accomplish this with dynamic data?
12/16/2008 2:38:51 PM


Modify your table and check the Allow Nulls box for the field you wish not to validate.

The ID which should be the first field in the table should NOT allows NULL's always.

If you go to 'Column Properties' which is at the bottom of SQL Server 2005. You can set a 'Default Value or Binding'. For example if you type in getdate(), it will automatically insert todays date.

You could also default it to 1 or 0. Good if you are using checkboxes. You would need to make it a TinyInt if using checkboxes.

Any other questions?

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. Check out
12/16/2008 2:53:28 PM
What is the right way to accomplish what I've asked without modifying the table?
12/16/2008 3:00:10 PM

The best way is to modify the tables. I strongly recommend doing it that way.

It would be sloppy programming any other way if you dont use validation and less secure.


Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. Check out
12/16/2008 3:07:49 PM
Well, in my case modifying the table is not an option. I am pretty sure that what I'm asking is possible by extending the table class or changing the field templates..
12/16/2008 4:06:58 PM

If you just want to validate a textbox why dont you just use for example,

<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Display="dynamic"

ErrorMessage="Enter Org Name" ControlToValidate="sOrgName"></asp:RequiredFieldValidator>



Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. Check out
12/16/2008 4:12:15 PM
I'm sorry, you've got me wrong.
What I'm looking for is actually an elegant way to disable the Required validation on some fields. They all are set to NOT NULL in the database and changing this is not an option for me.
12/16/2008 4:48:59 PM

My final suggestion. If this doesnt help. Try reposting this again so its brand new. People will respond faster to brand new posts.

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. Check out
12/16/2008 4:57:09 PM

It would be a mistake to change the schema to allow nulls - you don't want to do that. For some fields you want the DB to supply the value (via defaults from the DB). What you really want is allow NULL at the client (ASP.Net side) but not allow nulls on the server (the server will supply the value).

The easiest way to do this is with scaffoldColumn(false) to hide those columns. The problem with that approach is you never see the hidden fields - even on List and details pages where you are just reading them. You can use Steve's approach to hide the fields on insert. Look for hiding columns at 

Rick -ASP.Net UE  My DD Blog  DD FAQ
12/16/2008 5:34:35 PM

Similar Artilces:

Validators not Validating
Would anyone know why the validations on the page below wouldn't work. I am going through a book and learning and for some reason when I put in the last subroutine to insert the record the validation checks on the controls on the form no longer work.<%@ Import Namespace="System.Data.SqlClient" %><html><head><title>The Intranet Site</title><script runat="server" language="VB">Dim objConn As New SQLConnection("Server=XXXXXXX; database=Dorknozzle; uid=XXXXXXX; Pwd=XXXXXXXX;")Dim objCmd As SQLCommandDim objRdr As SQLDataReader  Sub...

Validator.Validate() ?
Hello guys,When I created a function to do custom validation I tried to use RegularExpressionValidator.Validate(). My code: 1 protected void EvaluateNewGateWay(object source, ServerValidateEventArgs args) 2 { 3 if (chBoxNewGW.Checked) 4 { 5 RegularExpressionValidator rev = new RegularExpressionValidator(); 6 rev.ErrorMessage = "REV Error"; 7 rev.ControlToValidate = "txtNewGW"; 8 rev.ValidationExpression = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?"; 9 rev.Tex...

using a validator to validate data
I need to use a validator to validate that data not related to a filed is present (basically I want to check that data related to the current record exists) and use a validation control so i can add it into the validation summaryI need some ideas on how to do this.Dylan Barberread my stupid blog hello.i think that you can combine a custom validator with the new call-back behavior to get the result you want...-- Regards,Luis Abreuemail: labreu_at_gmail.comEN blog:

Page.Validate() not validating custom validators
Hi,when i call Page.Validate("myGroup") The custom validators in the validation group myGroup  are not validated, i.e.  validator.IsValid returns true even if the validator failed on  page submit. code snippet: Page.Validate("ToolsImplementation"); foreach (IValidator validator in this.Validators) { if (!validator.IsValid) { //take action on validation failure } }   the code works fine except if valida...

.net validation vs custom validation
Hello, Coming from a background of Classic ASP. I have a logic of validation which also does out security and account. Basically, we use a stored proceedure to validate and then also log success, failures, attempts etc Can this be done using .net validation or i have to build my own validation logic ? And how is this done ? thanks Ehi You can use Custom validator control Using the CustomValidator Control  Hosam Kamel Remember to click on Mark as answer on the post that helped you...

Need an AJAX validator for dynamic validation
I have a user creation form to be used by a site administrator.  I need a validator that will check that the user name entered does not already exist and one that does the same for an email address. Stephen Walther had code in his books ASP.NET 2.0 Unleashed and ASP.NET 3.5 Unleashed that implemented an AJAX validator that does just this.  I've tried using the code he provided but there's a problem with it -- when the validator grabs the value of the textbox the validator is associated with, it reads it as an empty string instead of the value that was entered in the textb...

Dynamic HeaderText for Validation Summary to validate Repeater
Hi All,       I have a query regarding validating some server controls inside a repeater with the help of validation summary control .(The project is in 2.0 with C# as scripting language).     Actually the repeater gets bond as follows:       We have dynamic number of users(not more than 4). As per the number of users, that many items get repeated in the repeater.        There are some requiredfield and regularexpression validators inside the repeater to validate some textboxes,dropdown...

validating .net validation controls using javascript
 I need to validate multiple .net validation groups(a normal group would consist of RequiredFieldValidators, RegularExpressionValidators, ValidationSummary, etc) using javascript.  I am using Page_ClientValidate("GroupName") to validate the groups.  The problem arises when i validate multiple groups.  The validation summary and errors only appear for the last group validated or nothing appears if the last group validated returns true.  I want all validation summaries and errors to appear for all groups that return a false validation.  I'll never va...

Dynamic Validators are not so dynamic
Hello,I have some RequiredFieldValidators that aren't acting dynamic.  If I tab through my textboxes, none of them trigger the text message.                             <asp:RequiredFieldValidator ID="req_txtSenderName" runat="server" Display="Dynamic"                                        ControlToValidate="txtSenderName"                                         ErrorMessage="Test" />                        <asp:TextBox ID="txtSenderName" runat="server" MaxLength="100" /> What could be the problem? Thank you   Hi, I think you misunderstood the property Display="Dynamic"; actually it doesn't mean that validator will trigger on tab or mouse click event. It related to layout of error message displayed. Please read t...

Validation : required validator
HI All,I have created forms and given required and regular expression(email) validator  to some fields. It works fine on local But when i upload it on the live server, validatation not working.What could be the reason , Please let me know possible solution.ThanksAshok Naidu. Have you checked in Internet Explorer?Girijesh Please describe how exactly it does not work. Any runtime errors?Alexander TurlovMCSD.NETToronto, ON, Canada Hi. Validation controls generally depends on the properties like: ControlToValidate: Control id to be validated ValidationGro...

Validation Question, Validate If ...
Okay here's my situation. I've developed my companies intranet thus far including a fully functional helpdesk. Well I want to try and enforce a few fields in our helpdesk...  I have a DataBound FormView with a "Status" Drop down List, A "Time worked" Text Box, and a "Comments" Text Box. What I want is when I set Status to "Closed" Time worked is required to be more then 0 and something has to be entered in comments.However, when the status is "Open", "Hold", or "Pending" these fields are not requir...

how to validate a chckbox with a validator?
How do i validate that a checkbox is checked with a validator?  which validator and how?   Hi, You may do this by coding using if statement. if(CheckBox.Checked) { do something..... } else { do }-SuganRemember to click “Mark as Answer” on the post If you get answer from this post(s) ! ...

client validation of validators
when you have validators across your page, is there a way to validate that they all passed on the client side? similar to Page.IsValid on the server. Reason being, I need to do some client side processing when all validations pass.Alvin ShihSoftware DeveloperMCP MCTS MCPD You might be able to do this by overriding the client-side validation functions that are auto-generated by ASP.NET.  If you look at the source HTML for a page with validators on, you should see JavaScript functions such as ValidatorOnSubmit() and ValidatorCommonOnSubmit().  If you add some more script after these are defined on the page e.g. immediately before the closing HTML body tag, you may be able to do what you require: (function() { var oldFunc = (ValidatorOnSubmit.constructor == Function) ? ValidatorOnSubmit : null; if (oldFunc) { ValidatorOnSubmit = function() { // run the old validation function and store the result var result = oldFunc(); // do your custom processing here var myResult = myProcessing(); return (result && myResult); } } })(); Please mark helpful posts as "Answer" In your javascript code, call Page_ClientValidate('validation group name'). It returns true if the validation group is validate and false if not. Generally when it returns false, you also return false so that the event that called your code (onclick or form.onsubmit) wi...

Validating DDL is there a validator for this?
Hi, I have a simple dropdown list. It has a number of elements in it, but the default one says 'Please select...' Is there a validator I can use to make certain they chose something? Granted it isn't very hard to add to the post logic, but validators are really quick and easy to throw in (even faster than the bit of code I will need to write otherwise). I thought to use a range validator and set the range greater than 0, thinking that if the value of the selected Item changed it would pick it up, but this does not seem to be the case. My assumption is that this validator does...

Validation causing more validation?
I have a webform with textboxs that holds prices for some goods. If this price is positive, -1(Orderline declined) or -9(free of charge) the price is validated. However, if the price is positive or -9 I need to validate another field, the delivery date. Any suggestions on how to do this? I hope this makes sense and that you can help me, I looked in the validation tutorial, but didn't find an answer to my problem. /Rasped Having a look at what validators are available I reckon a CustomValidator is the one for you.Check out this link for more information.

Custom Validator not validating
Hi Everyone,Im fairly new to and am trying to create a custom validator. In the code I have posted I have created a custom validator for a DDL which makes a text box enabled if a setup file is selected from the DDL (among other options). The purpose of this text box is to provide a setup file path to include in some release info I am creating for an application. I have then created a custom validator to make sure a path has been included in the text box if it is enabled. The problem I am having is that for some reason my custom validator for my text field where the file path should b...

Validation Order for the validators
Hi,       I am using a combination of validators(also various validation groups) in my page;Is there any way to change the order in which the validators are fired?? Basically I am trying to change the sequence in which the validation messages appear(I have enabled the Showmessagebox property) Hi,They will fire in the order that they are placed on the page, if you want to change the order, just change the order on the page. I hope this helps, if it answers your question, don't forget to mark it as such for those who come afterwards.Regards,Garet...

Validating a validation group
Hi  I have a rare situation where i need to validate only a few validators in a web page and if those are not valid return.I mean suppose i have some validators in the group "TestValidators" and in button click event methodi haveIf(!Page.Isvalid) //// here i should validate only the validators in the validation group.      return;  Thanks For all your support.  Can use the page's validate function and pass it the validation group name you want  to validate & then then check the page's valid property.... Page.Validat...

validation with requiredfield validator
Hi I have some text boxes, some of them are mandatory (compulsory). I am using requiredfield validator it is working but i have four butons and i want to validate this only on save button click event and it should not validate for the remaining three buttons. thanks sridhar hai, set the CauseValidation property values to "false" for all button on which you don't need the validation to occur. ok..byeKiran Challa,MCP set the causesvalidation property of the remaining buttons to falseWessam Zeidan thanks......

Validators validating but not displaying
Hello!  I have a simple form inside an update panel.  On the form there is a dropdownlist that when a certain value is selected, brings up another textbox for the user to fill out (so this control causes a postback).  The problem is when the page is first loaded, and you hit the submit button the validators for all of the controls will all show up; however, once you cause a postback with that dropdownlist the validators will no longer show up (they are still validating, though.  The user just can't see why the form's not submitting since the validators aren'...

validate valid date
 i have been pounding my head on the wall...... how do you validate a date? here is what i'm using for regex its working great but its failing when i enter "09/09/009" here is the code:  <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtStartDate"                                        Va...

Why validation control validate after...
I am using asp file upload and apply requiredfield validator and it shows an error message when i click on button its work fine but after selectin of file i press again click button the file upload successfully but the error message display again after successfull execution how can i solve this...Remember to click “Mark as Answer” on the post, if it helps you. Hi, What error you encountered? And could you please post some code? You didn't refer to Ajax functionality. BTW if you put fileupload control into UpdatePanel, it is not available. UpdatePanel doesn't support fileupload.Vi...

Validator Doesn't Validate Initial Data
To give a simple example of my problem, If I have a textbox with the value 5 in it, and set a range validator on it for a range of 2 to 3, when the page is displayed, the validation message doesn't appear. It only appears to display the message if I change the value. Can somone explain what is going on here, and how can I force the validator to validate the initial data? By default, validators do not display their error message when the page is first shown. They assume that since the data came through your code, you have clean data that you are filling in. They assume that user data is...

forcing validation for all validators having different validation groups on a page
Hi friends,I have a page with two sections, say section A and section B with each section having its own submit button. I have assigned seperate validation groups for submit button and validators in each section. so partial validation on submit of each section is occuring perfectly. Now i've got a third submit button to submit whole page and i want all the validations to take place on click of this button before submitting the page, which is not taking place because of the validation groups i have assigned. can anybody help me with this.Thankspushpendra Home Is Where the Win...

Web resources about - To validate or not to validate -

Credit Card Validate on the App Store on iTunes
Get Credit Card Validate on the App Store. See screenshots and ratings, and read customer reviews.

Who Is Going to Shoot Obama? Paul Broun Chuckles, Validates Question - YouTube
Republican Congressman from George Paul Broun chuckles and does not even come close to denouncing a question asked by a constituent at a town ...

PM says MH370 debris find 'validates search'
Experts say recovered MH370 debris is consistent the area being searched in the southern Indian Ocean.

Spain's domination of England validates the Socceroos' search for identity
It is incredible to think that with all the billions of dollars of resources in the English game, their solitary success remains almost 50 years ...

Fracking report validates environmental concerns in N.W.T.
... Kenyon of the Pembina Institute. A director of the Pembina Institute in Edmonton says a new report on the risks of shale gas development validates ...

【medical-news】Study First to Validate That Singing Can Help People Learn a Foreign Language - 医药生命科学动态跟踪 ...
只是新闻而已Fernanda Ferreira’s family emigrated from Portugal to Canada when she was very young. There, like most Canadian children, she learned French ...

Supreme court validates private loans for rightful purposes
Supreme court validates private loans for rightful purposes

IXIA : Selected by China Network World to Validate High-Performance Cisco ...
IXIA : Selected by China Network World to Validate High-Performance Cisco ... 4-traders (press release) BEIJING - June 25, 2013 - Ixia (Nasdaq: ...

Bloomberg: Apple will argue that the digital signature it uses to validate code is protected as free ...
... that the company will be putting forward a rather unusual argument in court. Apple will argue that the digital signature it uses to validate ...

Like You Really Need To Validate Your Social Media Presence….
How many Fortune 500 companies are blogging and using social media, and what can law firms learn from them?

Resources last updated: 3/9/2016 6:40:51 AM