Analysis of ASP. net html Control Learning

Source: Internet
Author: User

ASP. net 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.

The ASP. net html control has two more attributes than the HTML Tag:

◆ ID attribute: indicates that the program uses this attribute to control and operate on objects. The object names 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.

HTML tags are stored in ASP. NET web page, ASP. NET will check whether there is a runat attribute in the HTML Tag. If not, it is treated as a general HTML Tag string and sent to the client browser for interpretation. If the runat attribute exists, it indicates that the tag is already an object-oriented tag. NET Page object. NET shared object class library load, so that ASP. the NET program can be controlled. After the execution is complete, the code is converted to HTML tags and downloaded to the browser of the client for parsing and execution together with common HTML tags.

Common attributes of ASP. net 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: Only all text strings are displayed without the HTML Tag function.

Examples of ASP. net html controls

Apply the InnerHtml and InnerText attributes of the HTML control to Web applications. 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 = "press me"

10 s1.innerhtml = "Kaiji news"

11 s2.innertext = "Kaiji Information Studio"

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 procedure is described as follows:

◆ Line 2-6: create components in the HTML control, such as <button> and <span>.

◆ Row 3rd: The OnServerClick attribute is an event supported by the Button object. It is triggered when you click the Button object. setting this attribute indicates that when the OnServerClick event occurs, the event program to be executed (this program is bl click ).

◆ Row 3: declare that the following programs are Script programs executed on the server.

◆ Row 8-12: declares a page load subroutine. The main content is to display text using the InnerText and InnerHtml attributes of the HTML control object.

◆ Row 13-16: bl-click Event program, which declares the object type variable Sender and event parameter e. The Sender Parameter Function indicates which object sends an event, the function of the e parameter indicates the relevant information when an event occurs. The Span control is used to display text. The Sender As Object, E As Eventargs Declaration must be added to every event program. The page_load subroutine does not need to be called. It is automatically executed when the webpage loads the control.

The Learning and explanation of ASP. net html controls is here, and I hope to help you.

  1. Introduction to ASP. net mvc Framework
  2. ASP. net mvc Framework to save UpdatePanel
  3. Use ASP. net mvc source code to find a solution
  4. ActionInvoker of ASP. net mvc Framework
  5. ASP. NET code hidden files

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.