Custom validator Controll

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael ALbanese

    #1

    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 ServerValidateE ventArgs)

    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="whites moke" colspan="4">
    Enter your Search
    Criteria&nbsp;& nbsp;
    <asp:CustomVali dator
    id="InputValida tor" runat="server"
    OnServerValidat e="InputValidat or_ServerValida te" Font-
    Bold="True" Width="372px" ErrorMessage="E rror : Please
    enter Search Criteria"></asp:CustomValid ator>
    </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:Butt on id="btnClear"
    runat="server" Text="Clear"></asp:Button>
    </td>
    </tr>
    </tbody>
    </table>
    </form>
    </body>
    </html>

Working...