Asp. NET controls and asp.net controls
I. web controls 1. text box controls
TextBox Control
Function Description: displays text and receives user input text.
Name prefix: Txt
ASPX code:
<asp:TextBox ID="TxtSample" runat="server" Text="TextBox Sample"></asp:TextBox>
Important attribute: Text displayed on the button
TextMode: sets the text mode. "Single" is a Single-line text box, and "Multiline" is a multi-line text box.
Rows: When TextMode is set to "Multiline", the number of lines displayed in the text box
Columns set the text box width
Maximum number of characters allowed in the MaxLength text box
Lable Control
Function Description: displays text and receives user input text.
Name prefix: Txt
Important attribute: Text display Text attribute
ToolTip prompt information
2. Transfer Control
ButtonWidget
Function Description: used to create buttons and execute commands.
Name prefix: Btn
ASPX code:
<asp:Button ID="BtnSample" runat="server" Text="Sample" />
Important attribute: Text displayed on the button
ImageButtonWidget
Function Description: displays clickable images.
Name prefix: BtnImg
ASPX code:
<pre name="code" class="html"><asp:ImageButton ID="ImageButton1" runat="server" />
Important attribute: OnClientClick the name of the function to be executed when the image is clicked. PostBackUrl: the URL of the target page that is returned from the current page when ImageButton is clicked.
HyperLinkWidget
Function Description: Create a text hyperlink or image hyperlink named Prefix: Hlk ASPX code:
<asp:HyperLink ID="HlkSample" runat="server" NavigateUrl="www.sample.com.cn">Sample</asp:HyperLink>
Important attribute: NavigateUrl URL
Image URL displayed by ImageUrl
Target framework name, such as "_ blank" and "_ top"
Comparison
3. Select controls
Radio control (RadioButton)
A single-choice control can select an option. A single-choice control usually needs the Checked attribute to determine whether an option is selected. There may be some relationships between multiple single-choice controls, these contacts are bound and linked by GroupName,
RadioButtonList)
Similar to the single-choice control, the single-choice control can only select one project. Unlike the single-choice control, the single-choice control does not have the GroupName attribute, but can list multiple single-choice projects. In addition, the single-choice control generates less code than the single-choice control.
Check box control and check group control (CheckBox and CheckBoxList)
When a voting system requires the user to be able to select multiple options, the single-vote control does not meet the requirements. ASP. NET also provides check box controls and check group controls to meet multiple selection requirements. The check box control and the check group control are the same as the single-choice control and single-choice control. They both use the Checked attribute to determine whether the control is selected.
4. List controls
DropDownList Control
The list control provides multiple options for users in one control, while avoiding incorrect options .. The most common event of the DropDownList control is SelectedIndexChanged. This event is triggered when the selected item of the DropDownList control changes,
ListBox list control
Compared with the DropDownList control, The ListBox control can specify whether multiple choices are allowed. When the SelectionMode attribute is set to Single, it indicates that only one item can be selected from the list box. When the value of the SelectionMode attribute is Multiple, you can press Ctrl or Shift to select multiple data items from the list.
BulletedList list control
Unlike the list control above, the BulletedList control can present a project symbol or number. If you set the BulleteList attribute to the rendering project symbol, when the BulletedList is displayed on the page, the list front-end displays the project symbol or special symbol.
.
DropDownList
The most common events of list controls are:
SelectedIndexChanged
,
When
DropDownList
This event is triggered when the selected item of the list control changes,
5. container controls
Panel
The panel control is like a container of some controls. You can include some controls in the panel control, and then operate on the panel control to set whether to display or hide all the controls in the panel control, to achieve the Special Purpose of the designer.
Ii. HTML controls
1. Introduction
The HTML control is a control (also known as a Server control) provided by ASP. NET. It is a component executed on the Server side and can generate standard HTML files.
Generally, standard HTML tags cannot dynamically control their attributes, usage methods, and receive events. tags must be controlled using other programming languages, which is inconvenient for ASP programming, it also makes ASP programs messy.
ASP. NET has developed a new technology in this area, that is, HTML Tag objectization to make programs (such as Visual Basic. NET, C #...) HTML tags can be directly controlled. HTML tags after objectization are called HTML controls.
2. Features
The HTTP control has two more attributes than the HTML Tag:
ID property: indicates that the program uses this property to control and operate on objects. The object name cannot be repeated.
Runat attribute: indicates that the object is executed on the server. This attribute must be added to all HTML controls. If the HTML control object does not need to be controlled by the program during program execution, the ID attribute can be omitted.
Common attributes of HTML controls
InnerHtml/InnerText. This attribute can be used to set the text to be displayed by the control.
InnerHtml: displays text and performs the HTML Tag function.
InnerText: displays only all text strings without executing the HTML Tag function.
3. Compared with Web controls
Advantages and disadvantages of web controls
Advantages and disadvantages of HTML controls
3. Verify controls
1. Form Verification control (RequiredFieldValidator) in ASP. NET, the system provides the RequiredFieldValidator verification control for verification. Use the RequiredFieldValidator control to specify that a user must provide the corresponding information in a specific control. If no information is entered, the RequiredFieldValidator control will prompt an error message.
Important attribute: Name of the control that is verified by ControlToValidate
Error Message
If InitialValue is empty and the content of the verified control is empty, the verification fails,
If it is not blank, the verification fails if the content of the verified control is the same as the InitialValue value.
2. The comparison verification control (CompareValidator) verifies the user input against a specific data type. This is because when a user inputs user information, it is inevitable that an error message will be entered. If you need to know your birthday, the user may input other strings.
CompareValidator checks whether the value in the control meets the requirements of developers.
Important attribute: Name of the control that is verified by ControlToValidate
Error Message
Type: the Type of the verified data. It can be a string, a value, or a date.
The relationship between Operator and the specified value
ValueToCompare specifies the value for size comparison
ControlToCompare specifies the control for size comparison
3. The range verification control (RangeValidator) can check whether your input is between the specified upper limit and lower limit. It is usually used to check numbers, dates, currencies, and so on.
Important attribute: Name of the control that is verified by ControlToValidate
Error Message
Type: the Type of the verified data. It can be a string, a value, or a date.
MinimumValue minimum value
MaximumValue maximum
4. RegularExpressionValidator)
The regular expression verification control is very powerful. It is used to determine whether the value of the input control matches the pattern defined by a regular expression, such as email, phone number, and serial number.
Important attribute: Name of the control that is verified by ControlToValidate
Error Message
ValidationExpression: the regular expression used for verification
5. Custom logic verification control (CustomValidator)
The custom logic verification control (CustomValidator) allows you to create a verification control using the custom authentication logic.
Important attribute: Name of the control that is verified by ControlToValidate
Error Message
ClientValidationFunction: client-side verification function. args. Value is the verification content, and args. IsValid is the verification result.
OnServerValidate server verification time, implemented through the event process, args. Value is the verification content, args. IsValid is the verification result
6. The ValidationSummary verification group control can verify multiple controls on the same page. At the same time, the ValidationSummary control uses the ErrorMessage attribute to display an error message for each verification control on the page.
If you do not want to Display the error of the inline verification control, set the Display attribute of the inline verification control to None, or set the Text attribute. When the validation error occurs, the Validator control displays Text (that is, the ValidationSummary control displays ErrorMessage)
Important attribute: ShowMessageBox displays the error message in the dialog box.
ShowSummary displays error information on the webpage
DisplayMode
Iv. User Controls and Custom Controls
1. Meaning
User Control
User Controls allow developers to easily define and compile controls based on application requirements. The programming technology used by the development will be the same as the technology used to write Web forms. As long as the developer modifies the control, all the controls on the page using the control can be changed.
Custom Controls
The custom control is ASP. NET, which can improve the reusability of program code, that is, a custom control can be used again in webpages, custom controls, or controls.
2. Comparison
Related reading:Learning HTML controls in ASP. Net
ASP. NET development Daquan chapter 5th. Basic controls for Web Forms
Introduction to common Asp. NET controls