473,480 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Custom Validator

90 New Member
I have developed a custom validator to see if the name is already present in the array, if present then error message is provided.I have a textbox(TextBox1) to enter a name a button (Button1) to validate.
The code that i did is as shown below.
Expand|Select|Wrap|Line Numbers
  1.  string[] names = { "Akash", "Ganga", "Sukaoi" };
  2. ServerValidateEventArgs svea = new ServerValidateEventArgs("names", true);
  3.     protected void Button1_Click(object sender, EventArgs e)
  4.     {
  5.         ValidateName(TextBox1.Text,svea);
  6.  
  7.     }
  8.  
Expand|Select|Wrap|Line Numbers
  1. public void ValidateName(object sender, ServerValidateEventArgs e)
  2.     {
  3.         foreach (string a in names)
  4.         {
  5.             if (e.Value.Equals(names))
  6.             {
  7.                 Response.Write("Name already exists");
  8.             }
  9.             else
  10.             {
  11.                e.IsValid = false;
  12.             }
  13.         }
  14.     }
  15.  
It runs but does not check for validation?
any help?
Oct 20 '08 #1
1 963
nateraaaa
663 Recognized Expert Contributor
# foreach (string a in names)
# {
# if (e.Value.Equals(names))
# {
# Response.Write("Name already exists");
# }
# else
# {
# e.IsValid = false;
# }
# }
Are you wanting to loop through each string in the string array to identify if a string in the array is = to e.Value? If so the code above is incorrect. You need to check if e.Value.Equals(a)

Expand|Select|Wrap|Line Numbers
  1. foreach (string a in names)
  2.          {
  3.              if (e.Value.Equals(a))
  4.              {
  5.                  Response.Write("Name already exists");
  6.              }
  7.              else
  8.              {
  9.                 e.IsValid = false;
  10.              }
  11.          }
Nathan
Oct 20 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1264
by: Mike P | last post by:
I have a Custom validator that has ControlToValidate set to a textbox that also has a Required and RegularExpression validator. When I run the webpage on my machine the custom validator...
2
380
by: Evgueni | last post by:
Hello, I am new to .NET, and a custom validator is giving me a lot of grief. I want to use a Custom Validation control and for some reasons it's not firing the validation procedure. I am using...
8
7807
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the...
5
2912
by: Mattyw | last post by:
Hi, I'm relatively new to Web Forms, I have been using Required Field Validators and Regular Expression Validators on a Web Form I am developing and everything works as expected using Visual...
2
1770
by: Alan Silver | last post by:
Hello, I have a custom validator on my page, and have the server-side code working fine. I want to add a client-side funtion as well, but am not sure how to wire it in so that it works with the...
9
3117
by: wardy1975 | last post by:
Hi All, Looking for a little expert advice on a few web standards issues. I am currently trying to understand the impact of web standards for a web application I work with. I have been doing a...
3
8230
by: Andy | last post by:
Hi folks, I have a customvalidator control that works properly if it isn't contained in an ASP:TABLE. But, when I place it inside an ASP:TABLE, I find that _ServerValidate doesn't get fired,...
0
1561
by: tsw_mik | last post by:
I have created a custom control. It has: -label -button -list of textboxes -list of dropdownlists. I want to use a custom validator to perform some validation, but somehow I can't fo it. The...
4
2094
by: Rick | last post by:
Hello, I built a composite web control that has a textbox and a date control. added my custom control on a webform where there are other standard controls. Each control on the form has a...
1
3762
gagandeepgupta16
by: gagandeepgupta16 | last post by:
Hi I am working on an entry form using validation controls in ASP.NET. I have two controls which requires custom validators, no issue in using plain custom validators. But when i am using...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7048
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6741
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4485
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2997
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.