Get the App
SLTechnology News&Howtos  ›  Development  › 

Necessity of ASP.NET server control view

Shulou Source: shulou.com Published: 2022-06-02 08:31:27 09月13日 Update

Editor to share with you the necessity of ASP.NET server control view, I hope you will learn something after reading this article, let's discuss it together!

The necessity of the ASP.NET server control view: if our server control needs a more complete GUI, such as controlling the additional properties of the HTML element, such as font, color, height, etc., then we should inherit from the subclass WebControl of Control to get the required basic performance. Derived from the WebControl class, you need to follow the usual convention:

1. Contains a reference to the namespace from System.Web.UI.WebControl

2. The Render method cannot be overloaded to provide data directly to the output stream, but should be overloaded to implement the RenderContents method.

3. In general, the derived class of WebControl ends up as a tag in the output stream, but if you want to use other tags, you should overload the tagKey or TagName attribute of WebControl.

ASP.NET server control view learning experience (or MS recommendation):

1. If the control generates non-visual elements or displays them to non-HTML clients, then you should choose Control as the symbol class inheritance. Such as the label

2. Inheritance from WebControl that provides HTML interface

3. When extending the modification function, you should derive from an existing control, but not from the System.Web.UI.HtmlControls namespace, because the vs.net designer does not recognize controls derived from this class

In order to support the designer and implement the design time, you need to consider attribute (metadata) programming.

View state of the ASP.NET server control view

One of the most important aspects of Web programming is state management, which is to solve the problem of state management based on the stateless http protocol. In the era of asp-like web programming technology, this is usually solved by the following technical means:

1 、 Session

2 、 Cookies

3. Hide variables

4. URL carrying parameters

However, all the above schemes have their own shortcomings, such as Session is not suitable for expansion, Cookies may not be available under certain circumstances, hidden variables are not easy to manage, URL has limited length and limited capacity..

Considering comprehensively, MS puts forward the concept of ViewState (view) based on hidden variable scheme, which saves the server-side control state between two ASP.NET pages through the view. How does the view work?

After processing a Web request, the page framework collects the state of all controls in the page control tree and creates a view object. Each Control has a ViewState dictionary to save its own state. When outputting html to the client, all ViewState is serialized into a string expression, which is sent to the client as an implied variable. Usually, we pass the serialization substring of the view between the server and the client, and the implicit variable of the last request will be sent back to the server for parallelization, and then "restore" to the server control. In essence, it is an implicit variable, but the management function of ASP.NET is added on the basis of the implicit variable, which is the essence of the view.

Control's EnableViewState determines whether the control agrees to hand over its state to automated view management.

When a control needs to save state, no one can support a "simple native" data type such as int32 boolean. If it is a more complex attribute value type, the programmer needs to provide a type converter to convert the value data into a string, or if not, use the costly binary serialization function (byte by byte). View data is passed through an additional summary to ensure that the data is not tampered with (but there is no guarantee that it will not be snooped; after all, base64 coding is almost plaintext).

After reading this article, I believe you have a certain understanding of "the necessity of ASP.NET server control view". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Controls views servers services states variables data properties management clients programming necessity functionality fundamentals clients situations labels types design Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Docker Huawei macOS Shulou Technology