Preface: Take a note and continue to record my basic ASP. NET knowledge.
The RadioButton control is rendered as <input type = "radio"/> on the client side. Like the server side control, the RadioButton control can also be grouped by the GroupName attribute.
The Button control is rendered on the client as <input type = "submit"/>
The LinkButton control is rendered on the client as <a href = "javascript :__ doPostBack"/>
The ImageButton control is a Button that allows you to set ImageUrl. It is rendered on the client as <input type = "image"/>
Similarities: You can set the OnClientClick attribute to "return confirm (Are you sure you want to delete it ?) ";
The Panel control is rendered as a DIV on the client. If the GroupingText attribute is set, the Panel control is rendered as <fieldset> <legend> Settings </legend> </fieldset>, that is, the GroupBox effect.
The Hyperlink control is rendered as a <a/> flag on the client.
You can set the properties NavigateUrl = "" and Target = "". If you set the ImageUrl attribute, it is rendered to <a href = ""> <image/> </a>.
The FileUpload control is rendered on the client as <input type = "file">.
Generally, the code for uploading files is written in this way.
If (FileUpload1.hasFile ())
{
String uploadPath = Server. MapPath ("~ /Upload /");
FileUpload1.SaveAs (uploadPath + FileUpload1.FileName );
}
In general, controls are divided into three types:
1) HTML controls
2) ASP. NET Server-side controls
3) HTML control with runat = "server"
Verify controls
1) RequireFieldValidator: A required field for non-empty server verification. common attributes include ErrorMessage, ControlToValidate, and InitialValue. you can write if (this. isValide ){...}
2) RangeValidator: determines whether the value is between the given maximum value (MaximumValue) and minimum value (MinimumValue). The comparable data types include string, int, and currency.
3) CompareValidator: used to compare whether the relationship between two values meets the requirements or data of the specified type. Comparison operators: <,>, = ,! =. Common attribute: ValueToCompare: Compare with which value, ControlToCompare: Compare with which control.
4) RegularExpressionValidator: a regular expression used to verify that the data meets the requirements. Common attribute: ValidationExpression: defines a regular expression.
5) CustomValidator: used for custom verification in special cases.
6) Note: (1) almost all verification controls must be verified on the client and server.
(2) group verification controls: ValidationGroup
(3) Whether to trigger the verification event: CauseValidation: false, indicating that the verification event is not triggered
(4) modify and verify whether the control is placeholder: Display is set to Dynamic or Static.
Data Binding
1) Example: <ItemTemplate> <% # Eval ("Id") %> </ItemTemplate>
2) The Repeater data control is used to bind the traversal display of data. Of course, you can also use the foreach statement to hand-Write the data.
3) Other Repeater control templates
(1) <AlternatingItemTemplate> set different styles of the row, that is, the style of the even row.
(2) The <HeadTemplate> and <FootTemplate> headers are displayed before and after the data, respectively, for example, <table> </table> or <ul> </ul> can be prevented.
(3) <SeperatorTemplate>, the delimiter between the two data items.
The database only stores the image path, ResolveClientUrl ("~ /Images/+ url ");
The controls placed in the <ItemTemplate> template cannot be operated directly in the c # code in the background. You must first find the controls by ID, such as e. Item. FindControl ("txtName ");
The Repeater control is generally used to display data only, while the ListView control is used to add, delete, change, and production operations.
Eval () is a one-way binding, used to read data in the database; Bind () is a two-way binding, which can read the values in the database to the page and upload user values to the database.
Considerations for the ListView control:
(1) automatically generated styles should be extracted into css styles rather than inline styles;
(2) in <ItemTemplate>, the <asp: Label> control is generally not required to display read-only data and output data directly.
(3) <LayoutTemplate> must have a server control with id itemPlaceHolder. Change the English fields automatically generated in the header to Chinese. Useless IDs must be deleted, and no need to be displayed.
Note the following in the ItemDataBound event:
(1) determine the data Row Type e. Item. ItemType = ListViewItemType. DataRow
(2) obtain the corresponding RowView ListViewDataItem lvDataItem = (ListViewDataItem) e. Item; DataRowView rowView = (DataRowView) lvDataItem. DataItem;
(3) When using FindControl, you should pay attention to the AlternatingItemTemplate problem.
Differences between ListView and GridView
(1) The GridView can only be rendered as a Table.
(2) ListView can be rendered to both Table and <ul> <li>
The DropDownList control binds the SelectedValue attribute, for example, SelectedValue = "<% # Eval (txtName) %>"
If the page front-end does not involve adding, deleting, modifying, and querying interactive information, you can disable ViewState in either of the following ways:
(1) Disable ViewState on the page as a whole: Add EnabelViewState = "false" to the <page> label on the top"
(2) Disable ViewState for the specified control: Add EnabelViewState = "false" to the property of the control"
Website Performance Tuning
(1) Cache is the first method for optimizing website performance;
(2) Index is the first way to optimize database performance;
How to Set page cache: In the page header area, set <% @ OutputCache Duration = "20" VaryByParam = "none" (this is variable and can be set as a parameter: id; num; age, etc.) %>
The data cache setting method sets attributes for ObjectDataSource,
(1) EnableCaching = "True"
(2) CacheDuration = "20"
Written behind: Mr. Lu Xun has a saying, "Where is a genius? I spent all my work and study on coffee! "I agree very much that diligence is good training. Now, let's get here today!