1. ASP. NET
CodeBehind: "cs after pre-aspx" mode,
(1) aspx (control definition, html, css) controls the page appearance and cs controls the Program Logic
Aspx is the template engine. You do not need to search for a third-party template engine.
(2) In aspx, the membership level for calling cs must be protected or public, but not private.
Because this currently executes the current subclass (via decompilation)
2,
Literal:
Mode attribute to prevent XSS attacks
TextBox:
AutopostBack = true focus left Textbox submit form
In ASP. NET, instead of directly calling submit, the _ doPostBack method is called to submit a form.
When the TestChanged event works with AutopostBack, you can click submit to automatically submit a form to update the input text.
Button: OnCLientClick
Return confirm ("are you sure you want to execute? ")
3. Button, LinkButton, and ImageButton allow multiple controls to share a processing function:
Set the Response Function in the command attribute.
CommandArgument = "daomul" (passing parameters through command parameters)
CommandName = "Remove" (name)
4,
Panal:
Rendering format of "Advanced Settings" (fieldset): GroupingText = "Advanced Settings"
HyperLink: it is convenient to reference internal resources in the site (automatic path conversion)
NavigateUrl attributes
5,
FileUpload:
FileUploadl. HasFile: whether the file is selected
FileUploadl. SaveAs ("root directory full path "):
Server. Mapath or VirtualPathUtility. ToAbsolute
Path = Server. Mapath ("~ /Upload /");
Vulnerability: (only files of the specified type can be uploaded)
System. IO. File. Delete (Server. Mapath .("~ /Upload /"));
System. IO. File. ReadAllText (Server. Mapath .("~ /Upload /"));
6. instance: registration page
Register. aspx
Copy codeThe Code is as follows: <% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "Register. aspx. cs" Inherits = "Login registration. Register" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Body>
<Form id = "form1" runat = "server">
<Div>
<Table border = "0" cellpadding = "0" cellspacing = "0">
<Tr>
<Td>
<Asp: Label ID = "LabelName" runat = "server" Text = "name"> </asp: Label>
</Td>
<Td>
<Asp: TextBox ID = "txtUserName" runat = "server" AutoPostBack = "True"
Ontextchanged = "txtUserName_TextChanged"> </asp: TextBox>
<Asp: Label ID = "errorMsg" runat = "server"
Text = "Label" CssClass = "error" Visible = "False"> </asp: Label>
</Td>
</Tr>
<Tr>
<Td>
<Asp: Label ID = "Label2" runat = "server" Text = "password"> </asp: Label>
</Td>
<Td>
<Asp: TextBox ID = "txtPassWord" runat = "server"> </asp: TextBox>
Password strength:
<Span id = "spanPassWord"> </span>
</Td>
</Tr>
<Tr>
<Td>
<Asp: Label ID = "Label3" runat = "server" Text = "Enter password again"> </asp: Label>
</Td>
<Td>
<Asp: TextBox ID = "txtPassWord_Second" runat = "server"> </asp: TextBox>
</Td>
</Tr>
<Tr>
<Td>
<Asp: Label ID = "Label4" runat = "server" Text = "Mailbox"> </asp: Label>
</Td>
<Td>
<Asp: TextBox ID = "txtEmail" runat = "server"> </asp: TextBox>
</Td>
</Tr>
<Tr>
<Td>
<Asp: Button ID = "btnRegister" runat = "server" Text = "register"
Onclick = "btnRegister_Click"/>
</Td>
</Tr>
<Tr>
<Td>
<Asp: Label ID = "LabelErrorMsg" runat = "server" Visible = "False"> </asp: Label>
</Td>
</Tr>
</Table>
</Div>
</Form>
</Body>
<Head id = "Head1" runat = "server">
<Style type = "text/css">
. Error {background: Red ;}
</Style>
<Title> Registered User </title>
<Script src = "Scripts/jquery-1.4.1.js" type = "text/javascript"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ("# <% = TxtPassWord. ClientID %>"). blur (function (){
Var str = $ (this). val ();
If (str. length <= 6 ){
$ ("# SpanPassWord"). text ("weak ");
}
Else {
// Contains numbers and letters
Var check =/\ w /;
If (check. test (str )){
$ ("# SpanPassWord"). text ("strong ");
}
Else {
$ ("# SpanPassWord"). text ("medium ");
}
}
});
$ ("# <% = Form1.ClientID %>"). submit (function (){
Var pas1 = $ ("# <% = txtPassWord. ClientID %>"). val ();
Var pas2 = $ ("# <% = txtPassWord_Second.ClientID %>"). val ();
If (pas1! = Pas2 ){
Alert ("the two passwords are inconsistent. Please enter them again ");
Return;
}
Var sEmail = $ ("# <% = txtEmail. ClientID %>"). val ();
Var check =/. + @. + /;
If (! Check. test (sEmail )){
Alert ("Incorrect email format, please enter it again ");
Return;
}
});
}); </Script>
</Head>
</Html>
Register. apsx. csCopy codeThe Code is as follows: using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using login registration. DAL. DataSet1TableAdapters;
Using System. Text. RegularExpressions;
Namespace login Registration
{
Public partial class Register: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
}
Protected void btnRegister_Click (object sender, EventArgs e)
{
// Check whether the server version meets the requirements: ELE. Me Password
If (txtPassWord. Text! = TxtPassWord_Second.Text)
{
LabelErrorMsg. Text = "inconsistent passwords! ";
LabelErrorMsg. Visible = true;
Return;
}
Regex reEmail = new Regex (@ ". + @. + ");
If (! ReEmail. IsMatch (txtEmail. Text ))
{
LabelErrorMsg. Text = "Incorrect Email format! ";
LabelErrorMsg. Visible = true;
Return;
}
LabelErrorMsg. Visible = false;
T_userInfoTableAdapter adapter = new T_userInfoTableAdapter ();
If (adapter. GetDataByUserName (txtUserName. Text). Count> = 1)
{
ErrorMsg. Visible = true;
ErrorMsg. Text = "the user name already exists. Please try again! ";
Return;
}
Long userId = Convert. ToInt64 (adapter. InsertUser (txtUserName. Text, txtPassWord. Text,
TxtEmail. Text ));
// Read Session login information
Session ["Login ID"] = userId;
Session ["Login mark"] = true;
// Set a public jump page that can pass Parameters
// Role 1: Tell the user that the registration is successful; Role 2: prevent the user from clicking refresh to repeatedly submit data
Response. Redirect ("target. aspx? Msg = registration is successful and will be switched to the login interface & RedirectURL = login. aspx ");
}
Protected void txtUserName_TextChanged (object sender, EventArgs e)
{
T_userInfoTableAdapter adapter = new T_userInfoTableAdapter ();
If (adapter. GetDataByUserName (txtUserName. Text). Count> = 1 ){
ErrorMsg. Visible = true;
ErrorMsg. Text = "the user name already exists. Please try again! ";
}
Else {
ErrorMsg. Visible = false;
}
}
}
}
The regular expression to be used:
INSERT data records: insert into [dbo]. [T_userInfo] ([sUserName], [sPassWord], [Email]) output Inserted. id VALUES (@ sUserName, @ sPassWord, @ Email)
(1. Add SQL statements,
(2) Add an output Insert. Id in the Insert statement.
(3) set the ExecuteMode attribute to Scalar.
7. differences among the three controls: html controls and server controls. Runat = server Control (BEST)
A1.Attributes ("aaa") = "attribute assignment ";
8. Verify the control
(1. RequiredFieldVal:
Control and display name to be set (CausesValdation focus removed) ----- null
Initial Value: InitleValue (enter a keyword, including the initial value of the drop-down box)
Validator commonalities
!!!!!!!!!!
If (! IsValid) {return ;}
If (this. IsValid) {// prevents the client from skipping verification. IsValid indicates whether all Validator entries on the page have passed
Label1.Text = "";
}
Else {
Label1.Text = "the client is filled in insufficient or has an error ";
}
ValidstionGroup group (the form can be submitted by a single group on the page, but not associated with other groups) is the same as the name of the button
(2. RangeValidator: range Verification
Maximum and minimum comparison
Date. Now. () under baidu
(3. Only RequiredFieldValidator can verify that the field is empty.
(4) CompareValidator: Comparison and verification (type verification, comparison with other controls ,)
ControlToCompare is set to the control to be compared
RegularExpression:
VaildationExpression Regular Expression Verification
CustomVaildate custom control Verification
ServerValidate server Verification Code
Clientvexceptionfunction
(5) ValidationSummary summarizes error messages
The difference between text and ErrorMsg. ErrorMsg is used in ValidationSummary,
Text is directly displayed in the verification control position.
MASTER:
// Controls on the Operation template page
Button btn = (Button) this. Master. FindControl ("Button1 ");
Btn. Visible =! Btn. Vissble;
This. Master. Mapath ();
The virtual path is converted to the client access path (not the Server Control ):
Src = "<% = ResolveClientUrl %>"
This. ResolveClientUrl ();
ResolveClientUrl: Consider the path of the current page
ResolveUrl: generate a path starting from the root