Introduction to ASP. NET page framework

Source: Internet
Author: User

The ASP. NET page framework component is a scalable universal language runtime programming model in the Web forms framework. It can be used to dynamically generate Web pages. ASP. NET page framework component is the rational evolution of ASP.. NET syntax is compatible with existing pages.) It is specially designed to solve a large number of key defects in the early model. In particular, it provides the ability to create and use reusable UI controls that can be reused. These controls can encapsulate common functions, thus reducing the number of code that page developers need to write; it enables developers to construct page logic in a clear and orderly manner rather than "Code together"); it uses development tools that provide powerful wysiwyg wyg wywyg WYSIWYG) the existing traditional ASP code is not transparent ). This article introduces some basic knowledge about ASP. NET page features.

Compile the first ASP. NET page

ASP. NET pages are text files with. aspx extensions. Pages are composed of code and tag), which are dynamically compiled and executed on the server to generate display content for the client browser or device that initiates the request. They can be deployed under the IIS virtual directory tree. When the browser client requests. ASP.. NET runtime) to analyze the target file and compile it. NET Framework class. This class can be used to dynamically process requests ,. the aspx file is compiled only when it is accessed for the first time. The compiled type instance is used repeatedly by multiple requests ).

We don't need to modify the code in the HTML file. We just need to change its extension to. aspx to create an ASP. NET page. For example, the following example shows a simple HTML page, which collects the user's name and category, and sends the form back to the original page when the user clicks the button:

 
 
  1. ﹤form action="intro1_vb.aspx" method="post"﹥  
  2. ﹤h3﹥ Name: ﹤input id="Name" type=text﹥  
  3. Category: ﹤select id="Category" size=1﹥  
  4. ﹤option﹥psychology﹤/option﹥  
  5. ﹤option﹥business﹤/option﹥  
  6. ﹤option﹥popular_comp﹤/option﹥  
  7. ﹤/select﹥  
  8. ﹤input type=submit value="Lookup"﹥  
  9. ﹤/h3﹥  
  10. ﹤/form﹥  

Note: Nothing happens when you click the "Lookup" button, because the. aspx file only contains static HTML and no dynamic content ). Therefore, the same HTML is sent back to the client, resulting in the loss of content in the form field text box and drop-down list.

Add simple code to the page

ASP. NET provides ASP. NET page framework syntax and ASP page is compatible. It supports <%> code rendering render) blocks, which can be used together with HTML content in the. aspx file. These code blocks are strictly executed when the page is displayed.

The following example shows how to add the font size to the rendering block in HTML by using <%> ):

 
 
  1. ﹤form action="intro2_vb.aspx" method="post"﹥  
  2. ﹤h3﹥ Name: ﹤input id="Name" type=text﹥  
  3. Category: ﹤select id="Category" size=1﹥  
  4. ﹤option﹥psychology﹤/option﹥  
  5. ﹤option﹥business﹤/option﹥  
  6. ﹤option﹥popular_comp﹤/option﹥  
  7. ﹤/select﹥  
  8. ﹤/h3﹥  
  9. ﹤input type=submit value="Lookup"﹥  
  10. ﹤p﹥  
  11. ﹤% Dim I As Integer  
  12. For I = 0 to 7 %﹥  
  13. ﹤font size="﹤%=I%﹥"﹥ Welcome to ASP.NET ﹤/font﹥ ﹤br﹥  
  14. ﹤% Next %﹥  
  15. ﹤/form﹥  

Note: The <%> code block in the preceding example is different from ASP. It is actually compiled, not explained by the script engine. This improves the running performance.

ASP. NET page framework developers can use the <%> code block to dynamically modify HTML output information. For example, the following code demonstrates how to use the <%> code block to explain the result returned by the client:

 
 
  1. ﹤form action="intro3_vb.aspx"﹥  
  2. ﹤h3﹥ Name: ﹤input name="Name" type=text value="﹤%=HttpUtility.HtmlEncode(Request.QueryString("Name"))%﹥"﹥  
  3. Category: ﹤select name="Category" size=1﹥  
  4. ﹤%  
  5.  Dim I As Integer  
  6.  Dim Values(2) As String  
  7.  Values(0) = "psychology" 
  8.  Values(1) = "business" 
  9.  Values(2) = "popular_comp" 
  10.  For I = 0 To Values.Length - 1  
  11. %﹥  
  12. ﹤% If (Request.QueryString("Category") = Values(i)) %﹥  
  13.  ﹤option selected﹥  
  14. ﹤% Else %﹥  
  15.  ﹤option﹥  
  16. ﹤% End If %﹥  
  17. ﹤%=Values(i)%﹥  
  18. ﹤/option﹥  
  19.  ﹤% Next %﹥  
  20. ﹤/select﹥  
  21. ﹤/h3﹥  
  22. ﹤input type=submit name="Lookup" value="Lookup"﹥  
  23. ﹤p﹥  
  24. ﹤% If (Not Request.QueryString("Lookup") = Nothing) %﹥  
  25. Hi ﹤%=HttpUtility.HtmlEncode(Request.
  26. QueryString("Name")) %﹥, you selected: ﹤%=HttpUtility.HtmlEncode
  27. (Request.QueryString("Category")) %﹥  
  28. ﹤% End If %﹥  
  29. ﹤/form﹥  

Note: although the <%> code block provides a powerful way to customize the text output information returned from the ASP. NET page, it does not provide a clear HTML programming model. The preceding example shows that developers who only use the <%> code block must manage the Page Status and intercept the sent value by themselves.

The concept and instance analysis of the ASP. NET page framework are introduced here. I hope it will help you understand the ASP. NET page framework.

  1. ASP. NET control usage tips
  2. Analysis of ASP. NET annotations
  3. Analysis on the use of ASP. NET trace
  4. Introduction to ASP. NET Request Object Attributes
  5. Analysis on adding watermarks to Images Using ASP. NET (VB)

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.