Compared with ASP. NET1.X, ASP. NET2.0 has brought a lot of changes. This series will look at the various new and improved controls in the aspect of controls. this series of articles assumes that the reader has. x controls are familiar, because 2.0 and 1. x will not be involved in many of the same parts, so we can focus on different parts to facilitate ASP. NET2.0 controls have a better understanding and faster understanding. (PS: this series is my own learning experience. I hope you can correct it .)
Let's get into the control Hall of ASP. NET2.0!
ASP. NET 2.0 introduces many new server controls to provide powerful declarative support for data access, login security, wizard navigation, menus, tree views, portals, and so on. Many of these controls use the core application services of ASP. NET for data access, membership and role, and personalized settings.
Currently, 2.0 of controls are divided into the following aspects:
Standard controls
Data Control
Verify controls
Logon Control
Navigation controls
Web Part Control
HTML Control
Because the Server Control inherits from the Control or WebControl class, the 2.0 Control has two more important attributes: EnableTheming (indicating whether the Control can have a topic ), skinID (SkinId that provides the control appearance ).
There is also a very useful method: Focus (set the input Focus for the control ).
Let's start with the standard controls. The first article will look at the changes to the existing controls in standard controls 1. X.
Literal:
Mode attribute: determines whether to convert text or encode text.
You can set the Mode attribute to the following values:
Transform (default): any tag added to the control is converted to adapt to the protocol of the requesting browser.
PassThrough: any tag added to the control is displayed in the browser as is.
Encode: any tag added to the control is encoded using the HtmlEncode method, which converts HTML encoding to its text representation. For example, the <B> tag is displayed as & lt; B & gt ;. Encoding is useful when you want the browser to display without interpreting the mark. Encoding is also useful for security and helps prevent malicious tags from being executed in the browser. This setting is recommended when strings from untrusted sources are displayed.
TextBox:
AutoCompleteType attribute: specifies the type of content input by the memory client.
This attribute can be used to remember various types of input, such as Email. The biggest advantage is that you only remember the type you want to save.
Button:
OnClientClick attribute: client script executed on the client OnClick.
The addition of this attribute greatly facilitates program development. You do not need to add the attribute through code to implement client scripts as before.
PostBackUrl attribute: gets or sets the URL of the webpage sent from the current page when the Button control is clicked.
This attribute allows you to use the Button control to perform cross-page sending. The default value is null.
UseSubmitBehavior attributes:
The property is set to true to enable the Button control to use client script-based sending back. If it is set to false, it is based on the ASP. NET sending back mechanism. (Call the _ doPostBack function)
LinkButton, ImageButton:
Similar to the Button, only the UseSubmitBehavior attribute is not available.
HyperLink:
ImageUrl attribute: displays the image Url.
After setting this attribute, the image link is displayed.
ASP. controls inherited from the ListControl class in NET2.0 have one useful property AppendDataBoundItems (get or set a value that indicates whether to clear the list items before binding data ). when this attribute is set to True, the list items and bound items can coexist.
For example, you can set "select a rule" as a list item and bind the data to the first item, so that you do not need to add the default item in the background code, which is very convenient.
DropDownList:
The preceding attributes are added, but the remaining attributes do not change much.
ListBox:
Row attribute: displays the number of visible rows.
CheckBox, CheckBoxList:
Almost unchanged
RadioButton, RadioButtonList:
Almost unchanged
Panel:
ScrollBars attribute: the appearance of the Panel scroll bar. (put the GridView on the panel, you can easily implement the GridView with the scroll bar)
GroupingText property: the title text of the child control contained in the panel control. The default value is an empty string ("")
DefaultButton property: the default button of the Panel.
You can place the TextBox Control and Button control in the Panel control, and then define a default Button by setting the DefaultButton attribute of the Panel control to the ID of a Button in the Panel. If you press Enter in the text box in the panel, this is the same effect as clicking a specific default button. This helps you use the project form more effectively.
The remaining controls are basically unchanged.
Summary:
This article focuses on ASP. NET1.X and ASP. the standard controls in NET2.0 are compared, and the changes of these controls in NET2.0 are written. This is mainly a brief introduction, which facilitates the following. X development-based programmers can quickly master the original controls of 2.0. for specific examples, refer to Microsoft's MSDN.
BulletedList:
This control creates an unordered or ordered (numbered) Item List, which are displayed as HTML ul or ol elements, respectively. You can specify the appearance of an item, project symbol, or number. You can also define a list item by statically defining a list item or binding a control to data. You can also respond when you click an item.
BulletedList and ListBox, DropDownList, and other ASP. NET list controls are derived from the same ListControl class, so their usage is similar to those of these controls. I believe you can get started quickly. Next, let's talk about some special attributes.
BulletImageUrl property: gets or sets the path of the image displayed for each project symbol in the BulletedList control.
BulletStyle attribute: Specifies the project symbol style.
It has the following styles:
Member Name Description
The Circle Project symbol style is hollow Circle.
The mimage project symbol style is a custom image.
The Disc project symbol style is solid circle.
The LowerAlpha project symbol style is lowercase letters (a, B, c ...).
The LowerRoman project symbol style is lowercase roman numerals (I, ii, iii ...).
NotSet does not set the project symbol style. The browser that presents the BulletedList control determines the project symbol style to be displayed.
The Numbered project symbol style is a number (1, 2, 3 ...).
The Square project symbol style is solid Square.
The UpperAlpha project symbol style is uppercase letters (A, B, C ...).
The UpperRoman project symbol style is an upper-case roman number (I, II, III ...).
DisplayMode attribute: Display Mode of the Project symbol list.
With this attribute, we can set the project to display in Text, LinkButton, and HyperLink modes.
Text: Display in Text mode.
The HyperLink value allows the list content to be displayed as a HyperLink. When you click the hyperlink, it locates the corresponding URL. Use the Value attribute to specify the URL to which the hyperlink locates. After the HyperLink mode is selected, the Target attribute can be set to open.
The LinkButton field allows the list content to be displayed as links. When you Click the link button, use the BulletedList. Click Event to send it back to the server.
HiddenField:
Provides a method to store but not display information on the page. For example, you can store user preference settings in the HiddenField control. To add information to the HiddenField control, set the Value attribute to the Value to be stored between two rounds.
This control is equivalent to <input type = "hidden">.
FileUpload:
The upload control is equivalent to <input type = "file">. Its usage is similar to <input type = "file">.
MultiView and View:
The MultiView and View server controls are used as containers for other controls and tags, and provide a way to conveniently display information to replace the View.
Use the MultiView and View Controls to execute the following tasks:
* The MultiView and View controls can be used as an alternative to creating multiple Panel controls.
* Create a multi-page form. The MultiView and View controls can provide similar actions as the Wizard controls. The Wizard control is especially suitable for creating a step-by-step form. The Wizard control also supports more built-in UI elements (such as headers and footers), "previous" and "Next" buttons, and templates. You can use the MultiView control to replace the Wizard if you want to create a display that is changed based on conditions (rather than in order) or if you do not need additional features supported by the Wizard control.
From the above introduction, we can know that the MultiView, View, and Wizard controls allow us to create multi-step operations more quickly and easily.
The usage of MultiView and View is very simple, which is equivalent to Panel. You only need to put any View into MultiView. The ActiveView attribute of MultiView can set the Index of the initial display View.
The next key is how to implement switching between multiple views. We have two methods.
Method 1:
You can add a Button control (Button, LinkButton, or ImageButton) to each View control ). Then, you can set the CommandName and CommandArgument attributes of each button as reserved values to move the MultiView control to another view.
The following table lists the reserved CommandName values and corresponding CommandArgument values.
CommandName value CommandArgument Value
NextView
(No value)
PrevView
(No value)
SwitchViewByID
The ID of the View control to switch.
SwitchViewByIndex
The index number of the View control to switch.
The following example shows a MultiView control that contains three View controls. Each View Control contains a Button control that moves to a specific View control.
Sample Code
<Asp: MultiView ID = "MultiView1" runat = "server" ActiveViewIndex = "0">
<Asp: View ID = "View1" runat = "server">
View 1 <br/>
<Br/>
<Asp: Button ID = "Button1" runat = "server"
CommandArgument = "View2"
CommandName = "SwitchViewByID"
Text = "Go to View2"/>
</Asp: View>
<Asp: View ID = "View2" runat = "server">
View 2 <br/>
<Br/>
<Asp: Button ID = "Button2" runat = "server"
CommandArgument = "View3"
CommandName = "SwitchViewByID"
Text = "Go to View 3"/>
</Asp: View>
<Asp: View ID = "View3" runat = "server">
View 3 <br/>
<Br/>
<Asp: Button ID = "Button3" runat = "server"
CommandArgument = "View1"
CommandName = "SwitchViewByID"
Text = Go to View 1 "/>
</Asp: View>
</Asp: MultiView> </div>
This method does not require code to implement View switching.
The second method is code control.
MultiView. ActiveViewIndex and MultiView. SetActiveView can be implemented.
Their differences are:
The MultiView. ActiveViewIndex method sets the index value of the View. The index of the View control is determined by the declared order of the View Control in the MultiView control. For example, the index of the first View Control declared in the MultiView control is 0.
The MultiView. SetActiveView method sets the specified View control as the active View of the MultiView control.