Custom validator Controll

  • Thread starter Thread starter Michael ALbanese
  • Start date Start date
M

Michael ALbanese

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>
 
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/default.asp?url=/library/en-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" <[email protected]>
| Sender: "Michael ALbanese" <[email protected]>
| Subject: Custom validator Controll
| Date: Tue, 22 Jul 2003 13:07:17 -0700
| Lines: 115
| Message-ID: <[email protected]>
| 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>
|
|
 
Back
Top