473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Custom validator Controll

I am developing a telephone directory for my company.

I have Fist Name, Last Name, Department and Phone Number
as fields. A user can search by entering data into any
one, or combination of these fields.

I have been trying to write a custom validation control
that will test each of the textboxes and reject the
request if they are ALL blank.

It sounds simple, and It seems like a Javascript would do
the trick, but I am at a loss to connect the function with
the submit action.

Any advice would be appreciated.

Thank You,

Michael Albanese
Here is the short version on my page and a feble
validation control.

<%@ Page Language="VB" %>
<script runat="server">

' Insert page code here
'

Sub InputValidator_ServerValidate(sender As Object, e
As ServerValidateEventArgs)

If txtLName.Text = "" And txtFName.Text = "" And
txtDept.Text = "" And txtPhone.Text = "" Then
sender.IsValid = False
Else
sender.IsValid = True
End If

End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<table cellspacing="0" cellpadding="2" width="90%"
align="center" border="0">
<tbody>
<tr>
<td style="FONT-WEIGHT: bold"
bgcolor="whitesmoke" colspan="4">
Enter your Search
Criteria&nbsp;&nbsp;
<asp:CustomValidator
id="InputValidator" runat="server"
OnServerValidate="InputValidator_ServerValidate" Font-
Bold="True" Width="372px" ErrorMessage="Error : Please
enter Search Criteria"></asp:CustomValidator>
</td>
</tr>
<tr>
<td style="FONT-WEIGHT: bold"
align="middle">
First Name</td>
<td style="FONT-WEIGHT: bold"
align="middle">
Last Name</td>
<td style="FONT-WEIGHT: bold"
align="middle">
Department</td>
<td style="FONT-WEIGHT: bold"
align="middle">
Phone</td>
</tr>
<tr>
<td>
<asp:TextBox id="txtFname"
runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox id="txtLname"
runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox id="txtDept"
runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox id="txtPhone"
runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td align="middle">
<asp:Button id="btnSubmit"
runat="server" Text="Submit"></asp:Button>
&nbsp;<asp:Button id="btnClear"
runat="server" Text="Clear"></asp:Button>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>

Jul 19 '05 #1
1 4043
Hi Michael,

The only thing left is to make use of the nicely validated data. All you
need to do is check the IsValid property of Page to work out if you can
proceed to update your database. Here is how your submit handler might look:

public sub OnSubmit(source as Object, e as EventArgs)
if Page.IsValid then
' Now we can perform our transaction.
end if
end sub

You can check this link for more information:
http://msdn.microsoft.com/library/de...us/dnaspp/html
/pdc_userinput.asp

Hope this helpful.

Best Regards,
Lewis Wang

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "Michael ALbanese" <ma*******@ci.stamford.ct.us>
| Sender: "Michael ALbanese" <ma*******@ci.stamford.ct.us>
| Subject: Custom validator Controll
| Date: Tue, 22 Jul 2003 13:07:17 -0700
| Lines: 115
| Message-ID: <01****************************@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcNQjNmGzUwTW8VxSjKiv6daslrBAQ==
| Newsgroups: microsoft.public.dotnet.general
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:102065
| NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| I am developing a telephone directory for my company.
|
| I have Fist Name, Last Name, Department and Phone Number
| as fields. A user can search by entering data into any
| one, or combination of these fields.
|
| I have been trying to write a custom validation control
| that will test each of the textboxes and reject the
| request if they are ALL blank.
|
| It sounds simple, and It seems like a Javascript would do
| the trick, but I am at a loss to connect the function with
| the submit action.
|
| Any advice would be appreciated.
|
| Thank You,
|
| Michael Albanese
|
|
| Here is the short version on my page and a feble
| validation control.
|
| <%@ Page Language="VB" %>
| <script runat="server">
|
| ' Insert page code here
| '
|
| Sub InputValidator_ServerValidate(sender As Object, e
| As ServerValidateEventArgs)
|
| If txtLName.Text = "" And txtFName.Text = "" And
| txtDept.Text = "" And txtPhone.Text = "" Then
| sender.IsValid = False
| Else
| sender.IsValid = True
| End If
|
| End Sub
|
| </script>
| <html>
| <head>
| </head>
| <body>
| <form runat="server">
| <table cellspacing="0" cellpadding="2" width="90%"
| align="center" border="0">
| <tbody>
| <tr>
| <td style="FONT-WEIGHT: bold"
| bgcolor="whitesmoke" colspan="4">
| Enter your Search
| Criteria&nbsp;&nbsp;
| <asp:CustomValidator
| id="InputValidator" runat="server"
| OnServerValidate="InputValidator_ServerValidate" Font-
| Bold="True" Width="372px" ErrorMessage="Error : Please
| enter Search Criteria"></asp:CustomValidator>
| </td>
| </tr>
| <tr>
| <td style="FONT-WEIGHT: bold"
| align="middle">
| First Name</td>
| <td style="FONT-WEIGHT: bold"
| align="middle">
| Last Name</td>
| <td style="FONT-WEIGHT: bold"
| align="middle">
| Department</td>
| <td style="FONT-WEIGHT: bold"
| align="middle">
| Phone</td>
| </tr>
| <tr>
| <td>
| <asp:TextBox id="txtFname"
| runat="server"></asp:TextBox>
| </td>
| <td>
| <asp:TextBox id="txtLname"
| runat="server"></asp:TextBox>
| </td>
| <td>
| <asp:TextBox id="txtDept"
| runat="server"></asp:TextBox>
| </td>
| <td>
| <asp:TextBox id="txtPhone"
| runat="server"></asp:TextBox>
| </td>
| </tr>
| <tr>
| <td>
| </td>
| <td>
| </td>
| <td>
| </td>
| <td align="middle">
| <asp:Button id="btnSubmit"
| runat="server" Text="Submit"></asp:Button>
| &nbsp;<asp:Button id="btnClear"
| runat="server" Text="Clear"></asp:Button>
| </td>
| </tr>
| </tbody>
| </table>
| </form>
| </body>
| </html>
|
|

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
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...
8
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
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
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...
2
by: Michael ALbanese | last post by:
I am developing a telephone directory for my company. I have Fist Name, Last Name, Department and Phone Number as fields. A user can search by entering data into any one, or combination of these...
9
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
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
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
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.