Home  >  Article  >  Backend Development  >  ASP.NET basic knowledge (2)

ASP.NET basic knowledge (2)

巴扎黑
巴扎黑Original
2016-12-20 13:37:101364browse

The RadioButton control will be rendered as on the client side. Like the server-side control, it can also be grouped through the GroupName attribute.

Button control will be rendered on the client side as

LinkButton control will be rendered on the client side as

ImageButton control is a You can set the ImageUrl Button, which will be rendered on the client as
The same point: you can set the OnClientClick property to "return confirm('Are you sure you want to delete?')";

The Panel control will be rendered into a DIV on the client side. If its GroupingText property is set, it will be rendered into
. Setting
in this way is the effect of GroupBox.

Hyperlink control will be rendered as
tag on the client side.

You can set the attributes NavigateUrl="" and Target="". If you set the ImageUrl attribute, it will be rendered into .

FileUpload control will be in The client renders it as .

Generally, the code for uploading files is written like this
if(FileUpload1.hasFile())
{
string uploadPath = Server.MapPath("~/upload/");
FileUpload1.SaveAs(uploadPath + FileUpload1.FileName);
}

In general, there are three types of controls:

1) HTML control
2) ASP.NET server control
3) with runat="server "HTML control

Validation control

1) RequireFieldValidator: a required field, which can be used for non-empty verification on the server side. Commonly used properties are: ErrorMessage, ControlToValidate, InitialValue. When verifying on the server side, you can write if(this.IsValide) like this {…}
2) RangeValidator: Determine whether the value is between the given maximum value (MaximumValue) and minimum value (MinimumValue). Comparable data types include string, int, currency.
3) CompareValidator: Used to compare two Whether the relationship between the values ​​meets the requirements or the specified type of data. Comparison operators include: <,>,=,!=. Common properties: ValueToCompare: which value to compare with, ControlToCompare: which control to compare with.
4) RegularExpressionValidator: Regular expression used to verify that data satisfies. Common properties: ValidationExpression: Define regular expressions.
5) CustomValidator: Custom validation for special situations.
6) Note: (1) Almost all validation controls must be verified on the client and server.
(2) Group the validation controls: ValidationGroup
(3) Whether to trigger the verification event: CauseValidation: false, which means the verification event is not triggered
(4) Modify whether the verification control takes place: Display is set to Dynamic or Static.

Data binding

1) For example: <%#Eval ("Id")%>
2) Repeater data control is used to bind the traversal display of data. Of course, we also It can be written by hand using foreach statement.
3) Other templates of the Repeater control
(1) Set different styles for alternate rows, that is, the style of even-numbered rows.
(2) and templates at the head and tail are displayed in front and behind the data respectively, for example, to prevent

or
    wait.
    (3), the separator between two items of data.

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

    The control placed in the template cannot be directly operated in the background c# code. The control must be found through the ID first. For example: e.Item.FindControl("txtName");

    The Repeater control is generally only used to display data, while the ListView control is more convenient for adding, deleting, and modifying 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 onto the page, and also transfer the user's values ​​​​to the database. .

    Notes on the ListView control:

    (1) The automatically generated style should be extracted into the css style and not made inline;
    (2) It is generally not necessary to use in The control displays read-only data and can be output directly.
    (3) There must be a server-side control with the ID itemPlaceHolder in . Change the automatically generated English fields in the header to Chinese. Unused IDs should be deleted and there is no need to display them.

    In the ItemDataBound event, please note:

    (1) Determine the type of data row e.Item.ItemType == ListViewItemType.DataRow
    (2) Get the corresponding RowView ListViewDataItem lvDataItem = (ListViewDataItem)e.Item; DataRowView rowView = ( DataRowView)lvDataItem.DataItem;
    (3) When using FindControl, you should pay attention to the AlternatingItemTemplate issue.

    The difference between ListView and GridView
    (1) GridView can only be rendered into Table
    (2) ListView can be rendered into both Table and

    • DropDownList control binds the SelectedValue property, such as: SelectedValue="<%#Eval('txtName')%>"

      If there is a pure display page that does not involve interactive information such as adding, deleting, modifying, etc. on the front end of the page, you can disable ViewState. There are two methods:
      (1) Page Disable ViewState as a whole: Add EnabelViewState="false" in the top tag
      (2) Disable ViewState for the specified control: Add EnabelViewState="false" on the properties of the control

      Website performance tuning
      (1) Cache is the first means of website performance tuning;
      (2) Index is the first means of database performance tuning;

      How to set page cache: Set< in the page header area ;%@ OutputCache Duration="20" VaryByParam="none" (This is variable and can be set as parameters: id;num;age, etc.)%>

      Data cache setting method, set properties for ObjectDataSource,
      (1) EnableCaching="True"
      (2) CacheDuration="20"

      Written at the back: Mr. Lu Xun has a saying, "Where is the genius? I spend all the time other people drink coffee on working and studying. ! "I strongly agree, it is a good lesson to be diligent in making up for your shortcomings. Well, that’s it for today!


    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn