In the first few articles of the small and medium has been for you to share a few articles on the implementation of validation control, today we specifically for the user login page to add input data validation function and verification code function.
Learning content
1, create the ASP.net application.
Double-click the file under the E:\Solution1 directory to run Visual Studio 2008. In the Solution Explorer panel, right-click the solution and choose Add-New Web site on the pop-up shortcut menu to create a new CHAP4 site.
2, on the site Default.aspx page first add a 6 row 2 column table, and add controls, design User Registration interface: Add 6 Texbox controls, respectively, user name, password, confirm password, qq,e-mail, verify code, add a button control, For submission.
3, after the password, add the control to RequiredFieldValidator, in the property panel text, enter "Enter Password", the same method for the following add a control ; add a CompareValidator control after the confirmation password, and then in the property panel, please confirm the password, change the ControlToValidate to TextBOX3, change the Controltocompar to TextBOX2, operator for equal; add the RegularExpressionValidator control after "QQ" to verify that the input data format matches a particular pattern and edits its properties. In the property panel, change to a malformed, in ValidationExpression to the Chinese postal code, to \d*.
Add a RegularExpressionValidator to the e-mail, also change to an error in the Properties panel, and select Internet e-mail messages in ValidationExpression. Change the ShowMessageBox to true on the error message and change the ShowSummary to false.
4, download the. dll file to add to the Toolbox
in Visual Studio 2008, in the Solution Explorer panel, right-click the site CHAP4 and select Add ASP.net folder to the bin command from the pop-up shortcut menu. In the pop-up dialog box, right-click the Bin folder, select the Add Reference command from the pop-up shortcut menu, and in the Add Reference dialog box, select the Browse tab, locate the WebValidates.dll file, and add it to the Bin folder.
5, drag and drop the control to the page and register.
6, write code generation Verification code.
public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{ C4/>if (! IsPostBack)
{
sncode.create ();
}
}
private bool Checkcode ()
{
if (SNCODE.CHECKSN (TextBox6.Text.Trim ()))
{return
true;
}
else
{
sncode.create ();
return false;
}
}
protected void Button1_Click (object sender, EventArgs e)
{
if (page.isvalid)
{
if (!) Checkcode ())
{
Response.Write ("<script>alert Error!") </scritp> ");
}}} protected void LinkButton1_Click (object sender, EventArgs e)
{
sncode.create ();
}
}
7, run Default.aspx.
Run Effect chart:
Summarize
Through learning to master the role and use of ASP.net validation control, and understand the common Third-party control, master the use of validation code control, Third-party control to add, you can update the verification code, the function can basically do the required.
The above is a small compilation of the implementation of user registration and verification of the full content of the function, I hope to help you learn.