.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Custom Validator

Posted By:      Posted Date: October 14, 2010    Points: 0   Category :ASP.Net


I have a C# web form (within a master page) and textbox - how do I validate it so that any input has to have a "AR" or "BR" prefix. I have started something along these lines:

                ARF Number
                <asp:CustomValidator ID="ValidatorArf" runat="server" ErrorMessage="PMO Ref!" ClientValidationFunction="jSValidate"
                    ControlToValidate="TextBoxArfNo" ValidationGroup="ValidationGroupCreateDesign"></asp:CustomValidator>
                <asp:TextBox ID="TextBoxArfNo" runat="server" MaxLength="50" />

Is this the best way forward? How do I write the validation script?

Thanks in advance!

View Complete Post

More Related Resource Links

Custom Validator


I need to validate a field that depends from a selection of a dropdownlist.

Like, if on dropdown the selected value is 'N' then validate. But it it's 'S', ignores validation;

Is there a way to do this with custom validator ??

I tried but, it's not working.

function chkEndereco(source, args){
   var cmbOnde = $('select[id$=comboOnde]');
   if(cmbOnde.val() == 'N')
      args.IsValid = (args.Value == '')
   if(cmbOnde.val() == 'S')
     args.IsValid = true

<asp:TextBox ID="Endereco" name="endereco" runat="server" AutoCompleteType="none" autocomplete="off" />
                                    <ajaxToolKit:TextBoxWatermarkExtender ID="wmEndereco" runat="server" TargetControlID="Endereco" WatermarkText="Endereço (rua, avenida, etc)" />
                                    <asp:RequiredFieldValidator ID="rqEndereco" runat="server" ErrorMessage="Ops! Faltou o endereço." EnableClientScript="true" ControlToValidate="Endereco" Display="None"/>
                                    <asp:CustomValidator ID="crqEndereco" runat="server" ErrorMe

Creating a Validator class for a custom activity

I created a new Workflow Activity Library and then added a new Activity called BindForm2Activity. After that I added a new class called BindForm2Validator and then placed an attribute to the BindForm2Activity to link it to the validator class.   Here is the code for each of the classes:   BindForm2Activity.xoml.cs: Code Snippet   using System;using System.ComponentModel;using System.ComponentModel.Design;using System.Collections;using System.Drawing;using System.Linq;using System.Workflow.ComponentModel.Compiler;using System.Workflow.ComponentModel.Serialization;using System.Workflow.ComponentModel;using System.Workflow.ComponentModel.Design;using System.Workflow.Runtime;using System.Workflow.Activities;using System.Workflow.Activities.Rules; using FormsCollection;using Utils; namespace ActivityLibrary{    [ActivityValidator(typeof(BindForm2Validator))] public partial class BindForm2Activity : SequenceActivity {        public static DependencyProperty FormToBindProperty = System.Workflow.ComponentModel.DependencyProperty.Register("FormToBind", typeof(FormsCollection.Form2), typeof(BindForm2Activity));         [Description("Form to bind a datasource to it ")]        [Category("BindForm2ToDataSource")]        [Browsable(true)]        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]        public FormsCollection.Form2 Form

custom validator

Is it possible to pass the maximum character length to validateCharacter, rather than just have it set in stone.<asp:CustomValidator ID="ValCharacter" ControlToValidate="txtCharacter"  OnServerValidate="validateCharacter"  Text="Too many characters" runat="server" Display="Dynamic" />        Protected Sub validateCharacter(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)        Dim iChars As Integer = 500        If args.Value.Length > iChars Then            args.IsValid = False        End If    End Subthanks.

Custom Validator on DDL&Textbox values

I need to write a 2 custom validators that works as follows: I have a formview (Formview1) with an EditItemTemplate. The validators need to validate values in "DropDownList1" and a textbox called "EndUserGUIDTextBox" If the value in DDL1 is ("Assigned" or "Assigned to End User") and the value of EndUserGUIDTextBox is ("unassigned" or "pending" or NULL) then I need a validator to fire and return {"GUID must be assigned when status is" & DLL1 value}. If the value in DDL1 is ("In Stock" or "In Repair") and EndUserGUIDTextBox is NOT ("unassigned" or "pending" or NULL), then I need a validator to fire and return {"GUID must not be assigned when status is" & DLL1 Value}. The validators needs to run and show in the formview when the UpdateButton in my Formview is clicked. I'm doing this in VB. Real noobie here! All help appreciated. Thanks,

Custom Validator inside PasswordRecovery...

Hello,   I am using a PasswordRecovery Control and have changed one of the validators to a custom Validator, however, OnServerValidate neer seems to get called.   Can someone tell me how to get the OnServerValidate to work correctly?   Thanks.

custom validator firring on text changed


hi all i have a custom validator i have written a javascript method for this validator;

this validator has been pot on a textbox that has auto post back is true .... now this validation  fires when the post back happens...

i dont want it to fire on the post back but only on button click

please suggest 

thanks in advance 


Custom Validator and Postback


Hello frnds

I have used custom validator in my asp.net website

I am using server side validation 

my page contains a textbox (txtName), and 2 combobox (CmbState and CmbCity) and some more controls

Now i want to validate my page using custom validator only when save button is clicked.

one of my combobox has implemented SelectedIndexChanged event. so whenever i change a value in that combobox, instead of firing SelectedIndexChanged event, my validation is fired and it is displaying error message of custome validator.

i want to do validation only when save button is clicked and not when postback is done by any of my controls on that page.

How can i do this? is there any way to do this?



custom control validator - can't set width property


 I am trying to set the width property of a custom control validator but it is not happening at all. The width of the validator control popup is constantly 100% width (the width="200px" below has NO effect at all)

here is my code:

 < asp:RequiredFieldValidator id="RqdDateChange" 
ControlToValidate="txtDateChange" ErrorMessage="<b>Required Field Missing</b><br />The Date of Change is required.&quo

Custom Controls in C# .NET

Embedding user controls in a Windows form is just like adding a simple button or text box that are already provided with .NET. These basic controls were written essentially like you code your own controls. Typically the controls you design are to be used in multiple forms or to modularize your code. These reasons help reduce the amount of code you have to type as well as make it easier for you to change your implementation. There should almost never be any reason to duplicate code because it leaves a lot of room for bugs. So, implementing functionality specific to your control in the control's source code is a good idea. This reduces code duplication as well as modularize your code, which is a good programming guideline.

Writing custom MembershipProvider

ASP.NET Membership mechanism allows to use the build-in server tables to store and retrieve user data. By default, this mechanism can only be used with SQL Server database to which Microsoft provides suitable MembershipProvider class.
Inheriting from this abstract class, developer can use his own table(-es) from any database and use any database engine other than SQL Server, like Oracle, DB2 etc.

Custom Editing Behavior for DataGridView TextBox Columns

For various reasons I'm using a DataGridView instead of a ListView, and while configuring the DataGridView to look like a ListView wasn't much of a problem, there's one thing that got on my nerves, which is the behavior of textbox cells in edit mode: It is much too easy to leave the edit mode accidentally, simply by pressing the cursor keys at the wrong time. For example when the text caret is positioned behind the last character of the textbox cell content, and you press the right arrow key

Write Custom WebParts for SharePoint 2007

The popularity of SharePoint Portal Server 2003 led Microsoft to tightly integrate the next SharePoint version, Microsoft Office SharePoint Server (MOSS) 2007, with its ASP.NET 2.0 WebPart framework. This tight integration enables the ASP.NET and SharePoint developer to do a number of things that previously weren't possible

Writing Custom Web Parts for SharePoint 2007

As I mentioned in an earlier blog post, SharePoint 2007 is built on top of ASP.NET 2.0, which means you can now use ASP.NET 2.0 features (Forms Authentication, Master Pages, Membership, Site Navigation, New Data Controls, etc) when building SharePoint sites. This is true for both the new Windows SharePoint Services 3.0 version (which will be a free download) as well as Microsoft Office SharePoint Server 2007 (which costs money).

Custom views on .aspx webpage


Hi again, i have a client that needs me to create a custom view on thier webpage similar to Microsoft Word.

It goes about that, when I click on an image it redirects me to another page and must create a custom view for a certain paragraph on that page. I am not sure how to do this and wonder if anyone knows how.

I am using C# programming language if that helps at all. I Heard that using javascript would work but i dont know javascript yet so is there any alternative?

Set Custom Paper size in C#.net 3.5


Dear All,

I have to set custom paper size 6X8 inches

plz tell sugest me code how to do it.

in C#.net 3.5

i m using Asp.net 3.5 Crystal report

i have to do it programiticlly



Validator code keeling over


I'm posting in this forum, as it seems the best place for looking at some horrible Javascript!  In essence, I'm trying to hook into a RangeValidator on the client side - nothing special, just asking it to revalidate.  So, I have this in my VB:

 objDescriptor.AddProperty("DateRangeValidator", rvDateInput.ClientID)

and this in my JS: 

// First the constructor
this._DateRangeValidator = null; 

// Then the prototype
get_DateRangeValidator: function () {
        return this._DateRangeValidator;

    set_DateRangeValidator: function (value) {
        this._DateRangeValidator = value;


That's no different from many of the other references I am passing around, and which all work.  So, I'd expect this:


to "just work" and re-evaluate the validity - I think!  What I am actually seeing is:

function ValidatorUpdateDisplay(val) {
    if (typeof(v

How to implement custom HttpContext for each request under class that implements IHTTPHandler


Hello All,

I created an application and implemented IHTTPHandler for all incoming request ending with ".aspx" extension.

Under "ProcessRequest" module, I am creating an instance of HttpContext (with URL attributes different from my application's URL i.e. if I am working on localhost then speciying Yahoo.com as its URL) and assigning it to "context" which comes as method argument.

After redirection, an error is generated. Also, the custom HTTPContext is not passed to the requested page (default.aspx, in my case.)

Code is as follows.

    Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
            Dim requestedUrl As String
            Dim targetUrl As String
            Dim urlLength As Integer
            'Save settings which will be used while redirecting to appropriate page
            requestedUrl = context.Request.RawUrl
            If requestedUrl.IndexOf("?") >= 0 Then
                targetUrl = requestedUrl.Substring(0, requestedUrl.IndexOf("?"))
                targetUrl = requestedUrl
            End If
            If targetUrl = Nothing Or targetUrl.Length = 0 Then
                targetUrl = requestedUrl
            End If
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend