1

I am usingh VB.net, I have two textboxes please see below:

<tr id="trCheckedBy2" runat="server">
    <td>
    Application Checked by 1:
    </td>
    <td>
    <asp:TextBox ID="CheckedBy1TextBox" runat="server" Text='<%# Bind("CheckedBy1") %>' />
    </td>
    <td>
    Application Checked by 2:
    </td>
    <td >
    <asp:TextBox ID="CheckedBy2TextBox"  runat="server" Text='<%# Bind("CheckedBy2") %>' />
    </td>                                
</tr>

Now I want to give error message "Username can not be same" when CheckedBy2TextBox text is same as CheckedBy1TextBox. It would be good if we can use .net validator.

Please suggest!

Thanks.

Best Regards, MS

1 Answer 1

3

Use a CompareValidator control with the Operator property set to NotEqual:

<asp:CompareValidator runat="server"
                      ControlToValidate="ID_Of_First_TextBox"
                      ControlToCompare="ID_Of_Second_TextBox"
                      Operator="NotEqual"
                      ErrorMessage="Error_Message_Goes_Here" />
Sign up to request clarification or add additional context in comments.

2 Comments

If you see my tr id is runat="server" it is not recognizing my comparevalidator. Its giving error " System.Web.UI.HtmlControls.HtmlTableCellCollection must have items of type 'System.Web.UI.HtmlControls.HtmlTableCell'. 'asp:CompareValidator' is of type 'System.Web.UI.WebControls.CompareValidator'."
I'm not sure why you are using <tr runat="server"> but if your <tr> tag is runat="server", you should set runat="server" on the <td> too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.