Pages

Subscribe:

Thursday, 4 October 2012

CompareFieldValidator code

comparefieldvalidator control use for the comparing the data from one control to another control.
for ex:password and confirm password textbox control, if does not match then give the ErrorMessage Password does not match

code for this....
<table>
<tr>
                        <td>
                            Password
                        </td>
                        <td>
                            <asp:TextBox ID="txtpswd" runat="server" TextMode="Password"  />
                         
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Repeat password
                        </td>
                        <td>
                            <asp:TextBox ID="txtconpswd" runat="server" TextMode="Password"  />
                            <asp:CompareValidator ID="compswd" runat="server" ErrorMessage="Password does not match"
                                ControlToCompare="txtpswd" ControlToValidate="txtconpswd"></asp:CompareValidator>
                        </td>
                    </tr>

Required Field Validator code

if you want that any textbox control can not  be empty, then we use  the Required Field Validator Control


for ex:
you want that User Name Can not be empty.... then write that code for this...


UserName
<asp:textbox id="txtusername" runat="server"></asp:textbox>
<asp:requiredfieldvalidator  id="rqdrusername" runat="server" ContolToValidate="txtusername" ErrorMessage="Enter the UserName"></asp:requiredfieldvalidator >

Tuesday, 2 October 2012