tags:

views:

144

answers:

1

Hi,

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

+2  A: 

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" />
Mehrdad Afshari
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'."
MKS
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.
Mehrdad Afshari