PC Review


Reply
Thread Tools Rate Thread

Custom validator Controll

 
 
Michael ALbanese
Guest
Posts: n/a
 
      22nd Jul 2003
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>

 
Reply With Quote
 
 
 
 
Lewis Wang [MSFT]
Guest
Posts: n/a
 
      23rd Jul 2003
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" <(E-Mail Removed)>
| Sender: "Michael ALbanese" <(E-Mail Removed)>
| Subject: Custom validator Controll
| Date: Tue, 22 Jul 2003 13:07:17 -0700
| Lines: 115
| Message-ID: <01b401c3508c$d9863280$(E-Mail Removed)>
| 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>
|
|

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Custom Validator Joey Microsoft ASP .NET 0 23rd May 2007 07:57 PM
Custom Validator Deepak Mehta Microsoft ASP .NET 2 16th Feb 2005 05:22 PM
Custom Validator =?Utf-8?B?SmltIEhlYXZleQ==?= Microsoft ASP .NET 1 21st Jan 2005 06:01 PM
Custom Validator =?Utf-8?B?Vmk=?= Microsoft ASP .NET 1 30th Oct 2004 01:30 AM
custom validator Mike P Microsoft ASP .NET 2 5th Nov 2003 03:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:04 AM.