Introduction to asp.net HTML controls

Source: Internet
Author: User
Tags html tags

An HTML control is a asp.net-supplied control (also known as a server control), a component that executes on the server side and can produce standard HTML files. In general, the standard HTML tags can not dynamically control its properties, use methods, receive events, must use other programming languages to control the label, which is very inconvenient to use ASP programming, but also makes the ASP program more cluttered. Asp. NET has developed new technology in this area, which is to target HTML tags so that programs (such as Visual Basic.NET, C # ...) You can directly control HTML tags, which are called HTML controls after an object-formatted HTML tag.

HTTP controls have two more properties than HTML tags:

· ID attribute: Represents a program with this property to control and manipulate objects, and object names cannot be duplicated.

· Runat property: Indicates that the object executes on the server side, and all HTML controls must add this property. An id attribute can be omitted if the HTML control object does not need to be controlled by the program while it is executing.

When HTML tags are executed inside a asp.net web page, asp.net will see if there is a runat attribute in the HTML tag, and if not, the browser is sent to the client to perform an interpretation as a generic HTML tag string. If there is a runat attribute, it means that the label is already an object label. The ASP.net Page object will load the object's label from the. NET shared object class library so that the ASP.net program can control it, and then convert the HTML tag to the browser that is downloaded to the client with the generic HTML tag after execution.

Common Properties for HTML controls

Innerhtml/innertext. This property allows you to set the text to display for the control.

InnerHtml: Displays text and performs HTML tag functions.

InnerText: does not perform HTML tag functionality but only displays all text strings.

Example

Apply the innerHTML and InnerText properties of HTML controls in a Web page program. Program code:

01 02 <form runat="server">
03<button id="bl"runat="server"onserverclick="bl—click"/><p>
04<span id="s1"runat="server“/><br>
05<span id="s2"runat="server"/>
06 </form>
07<script language=“vb"runat="server">
08 sub page—load(sender as obj ect,e as eventargs)
09 b1.innertext="请按我"
10 s1.innerhtml="凯际资讯"
11 s2.innertext="凯际资讯工作室"
12 end sub
13 sub b1 click(sender as object,e as eventargs)
14 s1.innerhtml="<b>ASP.NET</b>"
15 s2.innertext="<b>ASP.NET</b>"
16 end sub
17 </script>
18

The instructions for this procedure are as follows:

· 第2-6: Create the components in an HTML control, such as <button>, <span>.

· Line 3rd: The OnServerClick property is an event that is supported by the button object and is triggered when the user clicks the buttons object, setting this property to indicate which event program to execute when the OnServerClick event occurs (this is BL click).

· Line 7th: declares that the following program is a script program that executes on the server side.

· 第8-12 Line: Declares a Web object loaded subroutine (page load) that displays text using the InnerText and innerHTML properties of an HTML control object.

· 第13-16: Bl-click Event program that declares the function of an object type variable sender and an event parameter E,sender parameter refers to which object emits the event, and the function of the e parameter indicates information about the event, and the span control is used to display the text. The declaration of (Sender as object,e as Eventargs) is added to each event program. The Page_Load subroutine does not need to be invoked and is automatically executed when the Web page loads the control.

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.