Asp. NET Basics (ii)

Source: Internet
Author: User
Tags website performance
The RadioButton control is rendered as <input type= "Radio"/&gt on the client, and as with the server-side controls, it can be grouped by groupname attributes.

The button control is rendered as <input type= "Submit" on the client/>

The LinkButton control renders as <a href= "Javascript:__dopostback" on the client/>

The ImageButton control is a button that can be set ImageUrl, which renders <input type= "image" on the client/>
The same point: you can set the OnClientClick property to "return confirm (' OK to delete? ')";

The Panel control renders a div on the client, and if its GroupingText property is set, it is rendered as a <fieldset><legend> setting </legend></fieldset The effect of GroupBox.

The hyperlink control renders the <a/> tag on the client.
You can set the property navigateurl= "" and target= "", if the ImageUrl property is set, it will be rendered as <a href= "" ><image/></a>.

The FileUpload control is rendered as <input type= "file" on the client.
The code that generally uploads the file is written like this
if (Fileupload1.hasfile ())
{
String uploadpath = Server.MapPath ("~/upload/");
Fileupload1.saveas (Uploadpath + fileupload1.filename);
}

Overall, the controls are divided into three types:
1) HTML control
2) ASP. NET Server Control
3) HTML control with runat= "Server"

validation controls
1) Requirefieldvalidator: Required fields, can be used to service the non-null check, Common properties are: errormessage, ControlToValidate, InitialValue. You can write the if (this) on the server side of the validation. Isvalide) {...}
2) RangeValidator: Determines whether the value is between the given maximum value (MaximumValue) and the minimum (MinimumValue), the data types that can be compared are string, int, currency.
3) CompareValidator: The relationship that is used to compare two values satisfies the required or specified type of data. Comparison operators are: <,>,=,!=. Common properties: ValueToCompare: Compare with which value, ControlToCompare: which control to compare.
4) RegularExpressionValidator: A regular expression used to verify data satisfaction. Common Properties: ValidationExpression: Defines a regular expression.
5) CustomValidator: Custom validation for special cases.
6) Note: (1) Almost all validation controls have to be verified on the client and server side.
(2) Grouping validation controls: ValidationGroup
(3) Whether to trigger the checksum event: Causevalidation:false, which indicates that no validation events are triggered
(4) Modify whether the validation control occupies a bit: display is set to dynamic or static.

Data binding
1) Example: <itemtemplate><% #Eval ("Id")%></ItemTemplate >
2) Repeater data controls are used to iterate through the data, and of course, we can also write with a foreach statement.
3) Other templates for repeater controls
(1) <AlternatingItemTemplate> set the different styles of interlaced, that is, the style of even lines.
(2) <HeadTemplate> and <FootTemplate> head end of the template, respectively, displayed in front and back of the data, such as to prevent <table></table> or <ul> </ul> and so on.
(3) <seperatortemplate> a separator between two items of data.

Only the path of the picture is stored in the database, Resolveclienturl ("~/images/+ url");

Controls placed in the <ItemTemplate> template cannot be manipulated directly in the background C # code, and the control must first be found through the ID, such as: E. Item.findcontrol ("txtname");

Repeater controls are typically used only to display data, and the ListView control is more convenient for adding and removing adaptation operations.

Eval () is a one-way binding that reads data from the database; bind () is a two-way binding that allows you to read the values in the database to the page, and also to upload the user's values to the database.

Considerations for the ListView control:
(1) Auto-generated style to be refined into CSS style, do not make inline;
(2) <ItemTemplate> There is generally no need to use the <asp:Label> control to display read-only data, direct output can be.
(3) A service-side control with ID Itemplaceholder must be in <LayoutTemplate>. Change the table header automatically generated English field to Chinese, the useless ID to delete, no need to show it.

It should be noted in the ItemDataBound event that:
(1) Determine the type of data row E.item.itemtype = = Listviewitemtype.datarow
(2) Obtain the corresponding Rowview listviewdataitem Lvdataitem = (listviewdataitem) e.item; DataRowView Rowview = (DataRowView) Lvdataitem.dataitem;
(3) When using FindControl should pay attention to alternatingitemtemplate problems.

The difference between a ListView and a GridView
(1) GridView can only be rendered as table
(2) The ListView can be rendered as a table or as a <ul><li>

DropDownList controls bind SelectedValue properties, such as: Selectedvalue= "<% #Eval (' txtname ')%>"

If the page front-end does not involve the deletion and modification of interactive information such as the pure Display page, you can disable ViewState, there are two ways:
(1) Overall page disable ViewState: At the top <page> label Nega enabelviewstate= "false"
(2) Disable viewstate for the specified control: add enabelviewstate= "false" to the control's properties

Website Performance Tuning
(1) Caching cache is the first means of website performance tuning;
(2) Indexing index is the first means of database performance tuning;

How to set the page cache: in the header area <page> set <%@ OutputCache duration= "" "Varybyparam=" None "(this is variable, can be set to parameters: Id;num;age, etc.)% >

How to set the data cache, set properties for ObjectDataSource,
(1) enablecaching= "True"
(2) cacheduration= "20"

Written in the back: Mr. Lu Xun has a saying, "Where is genius?" I used to work and study for people who drank coffee! "Very much agree, Qinnengbuzhuo is good training." All right, let's get here today!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.