asp.net-server Control Instance Tutorial

Source: Internet
Author: User

The server's control tag is understood by the server.


Limited to traditional ASP
The following list copies the previous chapter:

<%response.write (now ())%></p>
</center>
</body>
</ Html>
  
  

The above code illustrates the limitations of the classic asp: the code block must be placed where you want the output to appear.

With classic ASP It is impossible to separate executable code from HTML itself. This makes web pages difficult to read and difficult to maintain.




asp.net-server control
Asp. NET has resolved the "Spaghetti code" problem, as described in the server control above.

The server's control tag is understood by the server.

There are three types of server controls:

HTML server Controls-Traditional H tml tags
Web server Control-the new a SP. NET Label
Validating server controls-for input validation



Asp.net-h tml Server Control
HTML server control HTML tag to understand the server.

HTML elements in the ASP.net file, by default, are treated as text. To enable these elements to be programmable, add runat = "server"

The HTML element for the property. This property indicates that the

, the content should be treated as a single server control. This property increases the identification of server controls. The reference ID can be used to manipulate the control server at run time.

Note: All HTML server controls must be in the runat = "server" attribute of a <form> tag. The runat = "server" property indicates that the

form should be processed on the server. The report also notes that the attached control can be passed through the server's script.

In the following example, we declare HtmlAnchor server-controlled. aspx file. And then

We manipulated the href attribute's HtmlAnchor control in an event handler (an event handler is a subroutine executing code for a particular event)

。 The Page_Load event is an event that many asp.net understand:

<script runat= "Server" >
Sub Page_Load
Link1. Href=http://www.111cn.net End
Sub
</script>


   
<form runat= "Server" >
<a id= "Link1" runat= "Server" >visit 111cn.net!</a>
</form>
</body>

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.