how to validate more than 1 field dynamically?

sharc

Member
Joined
Jul 11, 2005
Messages
11
Programming Experience
3-5
I've got these fields in a form that I all want validated dynamically:
<tr>
<td style="width: 20%;">User Name:</td><td style="width: 40%;">
<asp:TextBox ID="txtUserName" runat="server" TabIndex="1"></asp:TextBox></td>
<td style="width: 40%;">
<asp:RequiredFieldValidator InitialValue="" ControlToValidate="txtUserName"
Display="Dynamic" ID="valUserName" runat="server" ErrorMessage="Required Field."/>
</td></tr>

<tr>
<td>First Name:</td>
<td><asp:TextBox ID="txtFirstName" runat="server" TabIndex="2"></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator InitialValue="" ControlToValidate="txtFirstName"
Display="Dynamic" ID="RequiredFieldValidator1" runat="server" ErrorMessage="Required Field."/>
</td></tr>
<tr>

<td>Last Name:</td>
<td><asp:TextBox ID="txtLastName" runat="server" TabIndex="3"></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator InitialValue="" ControlToValidate="txtLastName"
Display="Dynamic" ID="RequiredFieldValidator2" runat="server" ErrorMessage="Required Field."/>
</td></tr>

But it won't work. . . why :( ? I have another field on there that checks to see if the password fields match, and that works dynamically. . but why not these? Can anyone please help?
 
Use compareValidator
PHP:
       <table>
            <tr>
                <td style="width: 20%;">User Name:</td>
                <td style="width: 40%;">
                <asp:TextBox ID="txtUserName" runat="server" TabIndex="1"></asp:TextBox></td>
                <td style="width: 40%;">
                <asp:RequiredFieldValidator InitialValue="" ControlToValidate="txtUserName" 
                Display="Dynamic" ID="RequiredUserName" runat="server" ErrorMessage="Required Field."/>
                </td>
            </tr>

            <tr>
                <td style="width: 20%;">Password:</td>
                <td style="width: 40%;">
                <asp:TextBox ID="txtPassword" runat="server" TabIndex="2" TextMode="Password"></asp:TextBox>
                </td>
                <td style="width: 40%;">
                <asp:RequiredFieldValidator InitialValue="" ControlToValidate="txtPassword" 
                Display="Dynamic" ID="RequiredPassword" runat="server" ErrorMessage="Required Field."/>
                </td>
            </tr>
            <tr>
                <td style="width: 20%;">Confirm Password:</td>
                <td style="width: 40%;">
                <asp:TextBox ID="txtConfirmPassword" runat="server" TabIndex="2" TextMode="Password"></asp:TextBox>
                </td>
                <td style="width: 40%;">
                
                <asp:RequiredFieldValidator InitialValue="" ControlToValidate="txtConfirmPassword" 
                Display="Dynamic" ID="RequiredConfirmPassword" runat="server" ErrorMessage="Required Field."/>

                <!-- check this out -->
                <asp:CompareValidator id="comparePasswords" 
                    runat="server"
                    ControlToCompare="txtPassword"
                    ControlToValidate="txtConfirmPassword"
                    ErrorMessage="Your passwords do not match up!"
                    Display="Dynamic" />
                </td>
            </tr>
            <tr>
                <td>First Name:</td>
                <td><asp:TextBox ID="txtFirstName" runat="server" TabIndex="3"></asp:TextBox></td>
                <td>
                <asp:RequiredFieldValidator InitialValue="" ControlToValidate="txtFirstName" 
                Display="Dynamic" ID="RequiredFirstName" runat="server" ErrorMessage="Required Field."/>
                </td>
            </tr>
            <tr>
                <td>Last Name:</td>
                <td><asp:TextBox ID="txtLastName" runat="server" TabIndex="4"></asp:TextBox></td>
                <td>
                <asp:RequiredFieldValidator InitialValue="" ControlToValidate="txtLastName" 
                Display="Dynamic" ID="RequiredLastName" runat="server" ErrorMessage="Required Field."/>
                </td>
            </tr>
        </table>
 
compare validator instead of required field validator to validate 3 fields that I want dynamically marked as required?
uhmmm. .. ok, can you give me a hint as to how I can do this?
 

Latest posts

Back
Top