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
<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>
<asp:Button id="btnClear"
runat="server" Text="Clear"></asp:Button>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
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
<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>
<asp:Button id="btnClear"
runat="server" Text="Clear"></asp:Button>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>