470,594 Members | 1,120 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

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 3893
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mike P | last post: by
5 posts views Thread by Mattyw | last post: by
2 posts views Thread by Michael ALbanese | last post: by
9 posts views Thread by wardy1975 | last post: by
3 posts views Thread by Andy | last post: by
reply views Thread by tsw_mik | last post: by
4 posts views Thread by Rick | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.