Page 76 - DCAP312_WEB_TECHNOLOGIES_II
P. 76
Web Technologies-II
Notes <p>
Password<br>
<asp:TextBox id= “TextBox1” runat= “server”
TextMode= “Password”></asp:TextBox>
<asp:CompareValidator id= “CompareValidator1”
runat= “server” ErrorMessage= “Passwords do not match!”
ControlToValidate= “TextBox2”
ControlToCompare= “TextBox1”></asp:CompareValidator>
</p>
<p>
Confirm Password<br>
<asp:TextBox id= “TextBox2” runat= “server”
TextMode= “Password”></asp:TextBox>
</p>
<p>
<asp:Button id= “Button1” onclick= “Button1_Click”
runat= “server” Text= “Login”></asp:Button>
</p>
<p>
<asp:Label id= “Label1” runat= “server”></asp:Label>
</p>
</form>
</body>
</html>
In this example, the Web form uses two Textbox server controls. One is for the user to enter
the password, and the second Textbox control requires the user to enter the password again
to ensure they did not mistype the original. By using the CompareValidator server control, we
guarantee that they are equal strings. If they are not equal, the page returns an error message
(See Figure 4.3). If they are equal, our page submits as valid.
Figure 4.3: The user mistyped the password and got an error message
70 LOVELY PROFESSIONAL UNIVERSITY