custom validator will not fire neither client side or server side

i am trying to validate a dropdownlist but the custom validation will not fire. i want it to fire if the user selects index=0 i have tried client side and server side validation but no luck. plz do not suggest using the required field validation becuse the value of index = 0 is not null or any other validation controll, i need to use the custom validation becuse iam also gonna validat other indexes .


<asp:DropDownList ID="categoryDropDownList" runat="server" DataSourceID="catSqlDataSource" DataTextField="cat" DataValueField="catvalue">
<asp:CustomValidator ID="catCustomValidator" runat="server" ErrorMessage="chosse category" ValidationGroup="add" ControlToValidate="categoryDropDownList">*</asp:CustomValidator>


client side code:


<script type="text/javascript">
function clientvalidate(source, args){
var dropdown =
if (dropdown.selectedindex == 0){
args.IsValid = false;
} else {
args.IsValid = true;


server side code:


    Protected Sub catCustomValidator_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles catCustomValidator.ServerValidate

If categoryDropDownList.SelectedIndex = 0 Then args.IsValid = False
args.IsValid = True
End If
End Sub
6/19/2007 1:04:07 AM 93655 articles. 6 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 21
Get it on Google Play
Get it on Apple App Store

Two issues:

1. When you assign ControlToValidate to something, the CustomValidator will not be fired if the current textual value of the control is "". If your first item has a <asp:ListItem value="">No selection</asp:ListItem>, then it will have that blank text problem. If using VS2005 or ASP.NET 2, also set ValidateEmptyText to true. If using ASP.NET 1.x, do not assign anything to ControlToValidate.

2. Make sure your post back event handler method tests Page.IsValid is true before attempting to using the data of the page.

Check out my article on Solving the Challenges of ASP.NET Validators:

--- Peter Blum
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
6/19/2007 4:59:28 PM

Similar Artilces:

Firing both Client side event and server side event for server side button
I am having some difficulties getting this to work.. I have button_click ( and ClientClick (Javascript).  Javascript is firing fine.  Server script is not. may be you have return return false in the in the javascript which is why its not firing server side event.You should add javascript evelt like thisbutton1.onclientclick = "functionname" Function should nopt return false. Vikram www.vikramlakhotia.comPlease mark the answer if it helped you...

form double validation- server side and client side
Hi! I would like to make a server side validation after calling a js function that makes the client-side validation. I do not understand couple of things: 1. Do i need a server side button or  a simple HTML submit button in order to call both of the tests? 2. How do i call a server side function which is written in csharp  after i finish my JS validation (the submit  button is calling the JS function for validation first.)- is it possible to call it directly from a js function? 3. I know that my toolbox on  contains validation controls who probably are b...

Validation Controls in .NET ( Client side or server side?)
 i have a very basic question. We have all these validation controls in ( required field, range validator and others) question is the required field validator is a server side control. So does that mean that it does a post back? it client side or server side control  The only controls that post back are buttons and other inputs where you set AutoPostback="True", such as a dropdownlist or a textbox.  Another way of posting back is using an UpdatePanel and placing a trigger in it for a specified control and/or event. All controls are considered clien...

Server side validation affecting client side validation
Hi there I have some client side validation that is working fine and enables/disables buttons based on user selections. This works great. However, when I perform server side validation using custom validators (like checking if the user has entered < HTML > tags or decimals in the integer boxes) and the server side validation returns isValid = false then all of the JavaScript validation that I've already done when the user clicked each control is lost. I don't understand why the enabled/disabled state of the control is not maintained.  What is calling the JavaScr...

Server Side Validation vs Client Side Validation
If your page is using client side validation for required fields, expressions, etc.     What are the benefits or disadvantages of using 'extra' server side validation for max lengths, parsing, etc? Both have their Advantages and Disadvantages... so give this a read Regards,Vinz"Code, Beer and Music" that's my way of being a programmer!How to get your Forum Question Answered | Blog | CodeASP.NET hi there, advantage: because you are using javascript some browsers for any reason may not sup...

client side validation vs server side validation
hello  i see a web form that consists of three controls :textbox,requiredfieldvalidator that weired to the textbox and a button within the click event of the button there is the following: if page.isvalid then response.redirect("Page is valid") else response.redirect("Page is not valid") end if according to my understandings: when the user does not fill anything in the textbox and then clicks the button the the page will not be submitted (i.e no request to the page will be happened or no postback will be happened) then no server event will be happened so it is sure when the us...

Firing server side validation & Client side confirm with a single button..
Hi All, I have a "Update" asp button. onclick of the button i need to check the server side validations like:if (!IsValidEmail(ctrlEmailAddress.TextBoxControl.Text.Trim())) {MessageBox.Show("Enter valid email address"); validateCheck = false; } After completion of this type of validations, i need to fire one javascript confirmbox saying "Are you sure you want to update this order?" with "Yes/No" options. All these things needs to be done in a single button click. Can any one help me to acheive this ..requirement?  -HemanthPlease rem...

avoiding redundant server-side validation after client-side validation
I see an inaccurate validation behavior on my (2.0) form. The EnableClientScript property of my validation control is set to True by default, so it performs the validation on clientside. But as soon as this occurs, it also performs the server-side validation, so the page refreshes. When the validation error occurs on clientside, it should not do the validation on serverside (I'm not calling Page.Validate() or doing Page.IsValid). In my past experience, handled this automatically, but I guess it's not always the ca...

Custom Validator
Hi, I am using the custom validator to validate something in the client side. It works fine in 3 different server. But it is not working fine in one server. Is it depend on server enviornment? My Code   <asp:CustomValidator id="cvCustVal" runat="server" EnableClientScript="True" ErrorMessage="The Application is required."ControlToValidate="ddlDropDown" ClientValidationFunction="fnValidate">*</asp:CustomValidator> JavaScript Code function fnValidate(source, arguments) { var DropDownValue = docum...

Validations client side or server side ???
Where should the validations (Required field, range, etc.) be done in an web page client side or server side?  As per my knowledge most of the validations are on client side using javascript, unfortunately it won't work if someone has disabled their browsers javascript option. what do we do in this case? Any suggestion please. Both... Client-side for rich client experience. Server-side for data validation and for clients who have disabled javascript. *Always* validate on the server side. You will still get the benefits of client-side validation on browsers setup to handle th...

Client side or server side validation???
I have multiple usercontrols each displayed by pressing a button and then change the apperance to a new user control and so on. I have to check that almost every field in this user controls have a value entered, and then indicate (e.g. with a red star) those textboxes that does'nt have a value entered. How should I do this in the best way, client side or server side with some validator? I have in mind that when using a server side validator, it may dissapear when making a postback. But I'm not sure, and I assume there is a way to come around this problem?What do you all say? Client side or s...

client side and server side validation\validator8.aspx&font=3 i am trying to do custom validation something similar to the above. I hv done the Severvalidate method in the code behind. What about the client validation? do i do it in code behind or in javascript as shown? The goal is to add text like this to the page:<script language='javascript'>function MyFunction(src, args){  // your logic to set args.IsValid here}</script>ASP.NET doesn't care if you typed it directly in...

How to Access/Pass Server Side Array Variable at Another Web Form's Client Side
Hi All,I struck up with some intrested senario at my application development...hope some body will guide me or sends me some code snippets....Thanks in advance.Senario is like A.aspx (using C# .net 2.0 as code behind) I am going to have a array variable basically it is an TWO Dimensional array after populating the values in array I need to redirect/ reload another web form B.aspx, here i need to access the array in B.aspx client side JavaScript.How can I do this...Thanks AgainRaju Dont do a redirect but use server.transfer. That way the previous page will still hold its value, ...

validation, is it better to have client side or use server side validator controls
 Hi All. I want to do validation on text boxes etc. Is it better to do client side validation or just use the server side validation controls?   Hi!  If for server side controls you mean RequiredFieldValidator, CompareValidator, RegularExpressionValidator, etc.. i can tell you that they use client and server validation. For instance if you use a RequiredFieldValidator, on the client will be a validation, but on the server this condition will be evaluated again. Probably one of the objetives of this is deal with client with javascript disabled. Of course I ...

Web resources about - custom validator will not fire neither client side or server side -

CSE HTML Validator for Windows (Official Site) - Powerful HTML Validator, XHTML Validator, CSS Validator ...
CSE HTML Validator is a powerful and easy to use offline HTML, XHTML, CSS, JavaScript, and PHP syntax checker, HTML validator, XHTML validator, ...

DNSSEC/TLSA Validator is a web browser add-on which allows you to check the existence and validity of DNS Security Extensions (DNSSEC) records ...

Feed Validator for Atom and RSS
F E E D Validator for Atom and RSS and KML Jump to navigation RSS Profile Support Added ( more ) Home · About · News · Docs · Terms Copyright ...

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

Not fare: new myki card validators lack account balance information
New myki card validators will not tell passengers what their fare is, nor their account balance, leaving unable to monitor their myki use as ...

Mozilla launches new JavaScript-based Add-ons Validator for developers
... that the validation tool provided by Mozilla is unreliable and difficult to use. Today the company announces that the old Python-based validator ...

Business Insider Built An Awesome Analytics Validator And You Can Use It
At a fast-growing media company like Business Insider, keeping accurate analytics is absolutely essential. Editors rely on our analytics dashboard ...

Jon Voight, Validator of Right-Wing Frenzy
Jon Voight was once known for his acting chops and, later, for fathering Angelina Jolie. These days? Well, he's known for his rabid right-wing ...

chocolatey/package-validator · GitHub
package-validator - Windows service to validate packages conform to pacakge standards

Bing Webmaster Tools Adds Markup Validator
The Bing Webmaster Blog announced they have added a new feature to the crawl section named Markup Validator. To access this new feature, login ...

Resources last updated: 12/25/2015 5:45:25 PM