Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

ASP.NET the underlying control


May 13, 2021 ASP.NET


Table of contents


The underlying control

In this section, we'll discuss the underlying controls that ASP.NET in the property code.

Button control

ASP.NET provides three different types of button controls:

  • Button: Displays text within the rectangular area.
  • Link button: Displays text like a hyperlink.
  • Image button: Displays the image.

When the user clicks a button, two events are triggered: click and instruction.

The basic syntax of the button control:

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Click" / >

Common properties of button controls:

Property Describe
Text The text appears on the button. Controls for buttons and chain buttons only.
ImageUrl For image button controls only. This image is intended to display buttons.
AlternateText For image button controls only. If the browser cannot display the image, the replacement text appears.
CausesValidation When the user clicks the button, determine whether page validation is performed. The default is true.
CommandName The string value passed to the command event when the user clicks the button.
CommandArgument The string value passed to the command event when the user clicks the button.
PostBackUrl The required page address appears when the user clicks the button.

Text boxes and labels

Text box controls are set specifically to accept user input. A text box control can accept input from one or more lines of text based on the properties of the text pattern.

Label controls provide an easy way to display text from one page to the next. If you want to display an unchanged text, you can use text text.

The basic syntax of body control:

<asp:TextBox ID="txtstate" runat="server" ></asp:TextBox>

Common properties for text boxes and labels:

Property Describe
TextMode Specify the type of text box. S ingle-line mode creates standard text, multi-line mode creates the ability to accept multiple texts, and passwords raise the input of characters to be tagged. The default is standard text.
Text The text content of the text box.
MaxLength Enter the text box Chinese the maximum value of this character.
Wrap It determines whether a multi-Chinese text box is automatically newer; The default is true.
ReadOnly Determines whether the user can change the text in the box; The default is false, i.e. the user can change the text.
Columns The width of the text box in the character. The actual width is determined based on the font used for text input.
Rows The height of the multi-line text box. The default value is 0, which represents a single line of text boxes.

The label control that mostly uses properties is 'Text', which represents the text that appears on the label.

Check boxes and turn buttons

A check box displays an option that the user can select or cancel. The turntable button renders a group of options where a user can select only one option.

If you want to create a set of turntate buttons, you can specify the same name for the group name properties in each turn button group. If more than one group needs to render a single form, specify the names of different groups for each group.

If you want to select a check box or a turn button as originally displayed, you can select the property as true. If multiple turn buttons are set to true in a set of properties, only the last one is considered true.

The basic syntax of the check box:

<asp:CheckBox ID= "chkoption" runat= "Server"> 
</asp:CheckBox>

The basic syntax of a turn button:

<asp:RadioButton ID= "rdboption" runat= "Server"> 
</asp: RadioButton>

Common properties of check boxes and turn buttons:

Property Describe
Text The text that appears next to the check box or the option button.
Checked Make whether to be selected, the default is unchecked.
GroupName The name of the control attributed to the group.

List control

ASP.NET provides the following controls:

  • Down-pull list,
  • List box,
  • a list of option buttons,
  • Check box list,
  • The bullet list.

These controls allow users to select from a list of one or more items. T he list box and the pull-down list contain one or more list items. These lists can be loaded by code or by the ListItemCollection editor.

The basic syntax of list box controls:

<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"    OnSelectedIndexChanged="ListBox1_SelectedIndexChanged">
</asp:ListBox>

The basic syntax of the pull-down list control:

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"   OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>

Common properties of list boxes and pull-down lists:

Property Describe
Items Represents a collection of ListItem objects for items within the control. This property is passed back to an object of the ListItemCollection type.
Rows Specify the number of items displayed in the box. If the actual list contains more rows than the displayed list, the scroll bar is added.
SelectedIndex The index of the currently selected item. I f more than one item is selected, the first index selects the item. If no item is selected, the value of this property is -1.
SelectedValue The value of the currently selected item. I f more than one item is selected, the value of the first item is selected. If there are no selected items, the value of the property is an empty string (")."
SelectionMode Indicates whether a list box allows a single selection or multiple selections.

Common properties for each list item object:

Property Describe
Text The text that is displayed for the project.
Selected Indicates whether the item is selected.
Value A string of characters related to the project.

The key points to focus on are:

  • If you want to work on an item in a pull-down list or list box, you need to use the project properties of that control. This property returns a ListItemCollection object that contains all items from the list.
  • SelectEdIndexChanged events are raised when a user selects a different item from a pull-down list or list box.

ListItemCollection

The ListItemCollection object is a collection of ListItem objects. E ach ListItem object represents an item in the list. In a ListItemCollection, the project number starts at 0.

The string used when an item in a list box is loaded is, for example: lstcolor. W hen Items.Add ("Blue"), the property setting for the value of the text and list items is the string value that you specify. To set it up differently, you must create an object for a list item and then add the item to the collection.

The ListItemCollection editor is used to add items to a down-and-down list or list box. I t is used to create static lists of items. To display the collection editor, select edit items from the smart label menu, or select controls, and then click the ellistore button in the item properties of the property window.

Common properties of ListItemCollection:

Property Describe
Item(integer) The ListItem object that represents the item at the specified index.
Count The number of items in the collection.

The basic approach to ListItemCollection:

Method Describe
Add(string) Add a new item at the end of the collection and assign string parameters to the project text properties.
Add(ListItem) Add a new item at the end of the collection.
Insert(integer, string) Specify the index location in the collection to insert the item and assign string parameters to the project text properties.
Insert(integer, ListItem) Insert items in the collection by specifying the location in the index.
Remove(string) Remove items with the same string as the text value.
Remove(ListItem) Remove the specified item.
RemoveAt(integer) Items that are removed from the specified index as integers.
Clear Remove all items from the collection.
FindByValue(string) Pass back items with the same string value.
FindByValue(Text) Pass back items that are the same as string text.

A list of turntr buttons and a list of check boxes

The list of turn buttons presents a list of mutually exclusive options. A check box list column presents a list of stand-alone options. These controls contain a collection of ListItem objects that can be referenced through the project properties of the control.

The basic syntax of a list of option buttons:

<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" 
   OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
</asp:RadioButtonList>

The basic syntax of the check box list:

<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True" 
   OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
</asp:CheckBoxList>

Common properties for check boxes and single button lists:

Property Describe
RepeatLayout This property specifies whether labels or normal HTML streams are used during the proposed formatting of the list. The default is a table.
RepeatDirection It specifies a direction in which the control can be repeated. T he available values are horizontal and vertical. The default is vertical.
RepeatColumns When a control is repeated, it specifies the number of the column;

Bullet list and number list

Bullet list controls create bulleted or numbered lists. These controls contain a collection of ListItem objects that can be referenced through the project properties of the control.

The basic syntax of bullet lists:

<asp:BulletedList ID="BulletedList1" runat="server">
</asp:BulletedList>

Common properties of bullet lists:

Property Describe
BulletStyle This property specifies the appearance or number of styles and item numbers.
RepeatDirection It specifies a direction in which the control can be repeated. T he available values are horizontal and vertical. The default is vertical.
RepeatColumns When a control is repeated, it specifies the number of the column;

Hyperlink control

Hyperlink HTML <a>

The basic syntax of hyperlink controls:

<asp:HyperLink ID="HyperLink1" runat="server">
   HyperLink
</asp:HyperLink>

It has the following properties:

Property Describe
ImageUrl The path to the image displayed by the control.
NavigateUrl The destination link address.
Text The text that is displayed as a link.
Target A window or frame that loads a linked page.

The image control

If the picture does not appear, the image control displays the picture on a Web page, or some alternate text.

The basic syntax of an image control:

<asp:Image ID="Image1" runat="server">

It has the following important properties:

Property Describe
AlternateText Alternate text is displayed when the picture does not exist.
ImageAlign Align option controls.
ImageUrl The path to the image displayed by the control.