ASP.NET: Revolution, not innovation

zhaozj2021-02-08  576

Microsoft originally only needs to be slightly improved on the web application platform ASP, providing a more functional server-side scripting programming language or page compilation function to maintain or even increase the popularity of ASP. In fact, ASP.NET provides these two features - but it also provides more things. Simply put, ASP.NET is a revolution. In this article, I will discuss the improvement of ASP.NET for web programming.

In the ASP model, a page is defined via HTML and then expanded by embedded scripts. In ASP.NET, the difference is that a page is a class that generates HTML. This model is called WebForm. If this name lets you think of the VB6's form control or .NET WinForms, then you touched it. For WebForms, the web server control is placed on a page. When this page is accessed, these controls automatically implement them in HTML. The complex process between the browser and the server is transparent to the programmer, and the server is automatically completed, and the event is processed, just like WinForms.

Welcome page

Let us start creating an example called Greter (welcome) and look at how it works. I like to unclear them when I learn a new technology and then make a whole piece. Greter just asks users to enter a name and issue a greeting message, but it demonstrates several main features of ASP.NET.

Greter page defines in two files: Greter.aspx, in list A, and Greter.aspx.cs, in list B. The .aspx file defines the UI (user interface) of the page, and the C # file (you can also use Visual Basic.net or JScript.net) to implement this page logic in the GreterLogic class. The @PAGE instruction of the first row of Greter.aspx files will be bind UI to the program logic by inheritance. The classname property in this instruction specifies the name of the UI class as CreteRUI. The inherits attribute specifies that Greeterui is inherited from Greterlogic.

Web server-side control

Several web server-side controls have been stated in the

assignment of this page. Web server-side controls are WebForm abstraction of standard HTML. They provide event handling and generate more features than standard HTML. The web server-side control is declared in an XML set of a reference ASP namespace. Every web server control in the .aspx file will cause an instance of the control when the page is executed. An instance of the control is created. References to each instance are held in their respective base classes. This allows the base class to access these controls and allowing it to control these controls and process events generated by these controls. Each web server-side control specifies the property runat = "server" to indicate that this control runs in the web server to generate a suitable HTML for the target web browser. The initial state of GREETER is shown in Figure A.

Figure A

The first three web server-side controls are quite intuitive: tag control (label), text box, and a submission letter. The last control, is different. A verification control checks the status of another control and prevents this form from being submitted when the target control is not in the correct state. In the Greter program, the RequiredFieldValidator control is used to verify that a data has been entered in the text box control. It doesn't care about the value of this data. In the initial state, the RequiredFieldValidator control is invisible. If the text box is empty when you are clicked, you will not generate a click message, and the RequiredFieldValidator control will display the properties of the errorMessage property, as shown in Figure B. For high versions of browsers, the RequiredFieldValidator control generates JavaScript to verify data on the client. For low version of browsers, you need to verify on the server side. ASP.NET also provides several verification controls in addition to the RequiredFieldValidator control. Figure B

Greterlogic class

GreeterLogic inherits from class system.web.ui.page. It declares several protected data domains to save references to controls created in the Greter.aspx file. Greterlogic defines two ways. OnInit method overloads the method to add a M_Button_Click method to the M_Button clicked event. The m_button_click method handles the click event generated by the M_Button web server-side control. This click event triggers a data transmission process to the server side. On the server side, ASP.NET restarts this page and then recover the status of the web server control. Now the value of the text box can be obtained by accessing the textboxText property. Figure C shows the response message generated by m_button_click.

Figure C

Configure the Greter program

To configure a Greter application, you can follow the steps below:

Create a directory for an application.

Create a bin subdirectory in the application's directory.

Place GREETER.ASPX in the application directory.

Use the command CSC / T: library /out:greter.dll Greeter.aspx.cs to compile Greter.aspx.cs into a library file and put Greter.dll in the BIN subdirectory of the application.

Create a IIS virtual directory pointing to the application directory.

.ASPX class

The ASP.NET application is processed by IIS ISAPI filter ASPNET_ISAPI.DLL. When you first access, the ISAPI filter generates a .NET class from Greter.aspx under the ASP namespace and compile it into a binary library file. IIS automatically searches for the BIN subdirectory of the application to find the GreterLogic base class. Figure D shows the inheritance relationship of the generated class. The generated binaries will be placed in a directory where the temporary ASP.NET file generated according to the virtual directory of the application. For example, if Greter's virtual directory is named by Introaspnet, Greter.aspx may generate a binary of Effla-HH.DLL and placed in C: /Winnt/Microsoft.Net/framework/v1.0.3328// Temporary ASP.NET FILES / INTROASPNET / B5D8B0AF / 51648AB7 in such a directory.

If Greter.aspx is modified, the ISAPI filter automatically regenerates binary files when the next page is accessed.

Figure D

ASP.NET is real-oriented

So what does all this mean? ASP.NET provides a true object-oriented programming model. WebForms can be created completely independent of the page logic, and combine it by inheritance. There will be no more inclusions of HTML and VBScript. The logic of the page is implemented using a full-featured .NET language, forces C #, Visual Basic.NET, or JScript.net. Further, the implementation process of page logic can use all the .NET base class libraries freely. The web server control encapsulates the difference between different web browsers and allows you to design the web page from a higher level. Everything will be compiled into a Microsoft Intermediate Language (MSIL) and can be converted into machine code synchronously at runtime. The performance loss that does not have existed in the interpretative page. If this is still not called a revolution, I really need a new dictionary :-). Listing A: Greter.aspx Greter.aspx </ title> </ head> <body> <form id = "queryname" method = "post" runat = "server"> <! - Heading -> <asp: label id = "m_Heading" runat = "server" font-bold = "true" font-size = "16pt" text = "please enter your name:"> <asp: label> < BR> <! - INPUT = "M_Label" runat = "server" font-bold = "true" text = "name:"> </ asp: label> <ask: textbox id = "m_textbox" runat = "server" width = "152px"> </ asp: textbox> <asp: button id = "m_button" runat = "server" text = "get Greeting"> </ asp: button> <br !> <- Input validation -> <asp: RequiredFieldValidator id = "m_Validator" runat = "server" ControlToValidate = "m_TextBox" ErrorMessage = "! You have not entered your name" ForeColor = "Red"> </ asp : RequiredFieldValidator> </ form> </ body> </ html></p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-514.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="514" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.044</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'R52sXyjKeWaUSWmxQUPZH_2FlK98NfEVtCs5_2BooDYrySCTQAYiqWiEIzir7hUPB6Q88DLu95buvCn9x5y7MYYtWw_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>