Asp.net control development series (1 and 2)

Source: Internet
Author: User

Some time ago, CS was popular among colleagues, so the greetings during that time became "have you killed XX today ?"

Control development is perhaps the most creative thing for programmers to discover themselves, right? Control development requires you to have a more comprehensive and slightly deeper understanding of the current development, but also promotes you to understand the underlying things of the development environment. For example, I have a deep interest in reflect and msil during the development of controls. Maybe, in the future, I will try to be a reflector. Haha, many things are hard to say ~

"Have you written controls today ?", It may become a common term for Chinese. Net programmers in the future. Haha, many things are hard to say ~ Sorry, I have already repeat it. After all, it is quite easy to develop some simple controls in the. NET Framework .. Net Framework has done most of the work for you (of course, I am wrong about this, and innovation is always the first .), I just want to tell you that it is really easy to use my three-inch tongue and enthusiasm.

Now, are you confident?

How many questions do I want to discuss with you?

1.asp.net is ASP +?

I remember a saying that Microsoft would like to change a brand-new name for something that doesn't need to be changed. This is a brand new technology, some completely different things have a very similar name. Asp.net and ASP are like this, And ado.net and ado.net are like this. Here, I want to say that Asp.net and ASP are very different. ASP is built on window DNA (this sentence may be incorrect and I have no idea about the old technology). It is interpreted as an execution method, while Asp.net is built on. net Framework, a brand new stuff, is first compiled and then run, so Asp.net is more efficient and has. net Framework supports a lot of functions, and it is very convenient. You do not have to make a haystack for a function in the com world, in a unified. it's okay to write and write code in the. NET environment. At the same time, as its fellow, Web Services has a lot of connectivity with Asp.net, you can conveniently provide services based on browsers and various Client GUI programs for the Internet, as well as remoting ..... it's so cool!

2.asp.net?

How does Asp.net generate dynamic and dynamic web pages? As a host, IIS creates AppDomains for each Asp.net program instead of processes. Each Asp.net program is compiled as a machine code at the first run to generate a response for the customer's request. When we create a webpage ,. aspx file and. aspx. CS files account for half of each other, and the pages are generated ,. the items in the aspx file are only a string of write calls of the render method.

3.where should we focus on ASP.net development?

Yes. Where should we focus? What skills should I focus on? In the above section, I said that the. aspx file is only part of a method (render) of the background program. Does it mean that the front-end is just a shit? I am absolutely opposed to this point of view for the following reasons: first, Asp.net eventually uses HTML, script, and CSS to implement the interface and complete the function. Only a render, but this render is not allowed. Isn't most of Asp.net's content ultimately for this render? 2 ,. the net framework has already done too many things for us. We can comfortably complete the functions we need, using system. use System to draw a watermark. what is the regular expression in the data-like operation data? XML ?...... There is a pile of wood waiting for you to pile up. Therefore, the road forward is clear, that is, using the old dhmtl/JS/CSS technology to complete your creativity. Another way is to study the software development methodology, what mode, what UML, what framework, what use cases, what MDA, what AOP ...... sorry, I can't take it anymore. It's not my strength. In addition, you do not have the foundation of DHTML in control development, and think that you can make a very successful control and idea for the deep development of existing controls? Basically... This (it's hard to take a nap during reading!

4. Attribute?

Attribute? This is an important concept in. NET and is especially important in control development. Many books say that attribute and property are difficult to distinguish. My understanding is very simple. Property is an internal attribute, and attribute is something relatively "external". For example, you have a big belly. This is property, and then you wear a loose dress. This is attribute. Of course, this explanation is absolutely incorrect, maybe the descriptive word "you have a big belly" is "attribute". However, this helps you understand the difference between the two. So what is the difference between the two? As we all know, I will try again here. When the compiler turns your code into an assemble, it turns the methods and properties into il commands. At the same time, it will produce a description of your classes, methods, attributes, fields and other information of metadata, so in IDE, I write a xx. after setting this point, a bunch of smart things that I love very much will come out. These are the credits of metadata and reflect. In addition, there is an Object Browser for vs.net, some of my brothers have all benefited from the tool that peeked at the internal code of my released controls, and IDE also uses reflection to read metadata to determine how the designer can interact with the controls. And! Attribute is the tool for operating metadata.

... What else? I didn't expect it for the moment, huh, huh.

Therefore, if you want to try to be a control brother, you should not only have confidence, but also prepare some basics such as HTML/JS/CSS and some understanding of the features of. Net such as attribute. Are you ready?

It may be because of my age, so I am not very calm in my work now, so I am not surprised to find several mistakes in the above section. At the same time, I am very grateful to you.

"Life and Death order"

"Installing Sun Tzu"

I wrote a lot of void theories in the first article. In this article, I will first talk about things that are "Big and specific": 1. Details of the life cycle of the Asp.net control (including the page itself; 2. How to Write a control.

"Life and Death order"

After receiving a user's page request, the Asp.net handler shows a fresh page to the client? What has it done? In what order?

To illustrate this problem, we must first understand that a page is also a control. From the perspective of the design pattern, the page model is a "composite", which is a structure tree composed of multiple layers of controls, and the top layer is page, the following controls have leaf branches, and leaf controls do not include sub-controls. Branches are controls that include sub-controls. A method to generate sub-controls is called for each layer of controls, the parent Control calls the generation method of the Child control, and the Child calls Sun's. This recursion ensures that all valid (visible = true) controls on the page are generated, (For details about the design mode, refer to the series of articles on the design mode of Dr. Lu Zhenyu's blog garden. This series of articles is about Dr. Lu's book "Java and mode" (88 yuan, very thick) can at least be used as a quick teaching material for the design model), and each control generally includes the following steps in the lifecycle:

  

1. instantiate)

Write controls are generally not exposed to this activity.

2. initialize (initialize)

Same as above.

3. Tracking View state )*

This method is important because it involves the view status. In general, you do not need to reload this method.

4. Load view State )*

This method will only be called during the return process. The usage is the same as above.

5. Load PostBack data )*

If your control needs to interact with the client after it is generated, this method is very important and will only be called during the return process.

6. Start loading)

This activity is generally managed only by the onload of the page. Do not use this method when writing controls.

7. There are modifications (raise changed events )*

After the control is generated, the data has been changed by the client, and it is the same as loading and returning data.

8. Raise PostBack event )*

It is generally used to convert client events into server events by controls that implement the ipostbackeventhandler interface. It is only used for the return process.

9. Generate a pre-processing (perrender )**

It is an important process to generate the preliminary work. You can use the onprerender method to implement customization.

10. Save view State )*

If viewstate [XXX] is used to save the information, you do not need to reload it. This method is reloaded only when you manage the custom view status, loadviewstate must be matched with the Save method.

11. Generate (render )***

This is the main character, and the control is basically managed here.

12. Unload)

13. Release (dispose)

Understanding the control lifecycle details is crucial for customizing all components of the control and debugging controls and eliminating control bugs.

Of course, we should pay special attention to some activities in this process. I added the * number behind these activities.

"Installing Sun Tzu"

Do you remember that I mentioned in my previous article that the. NET Framework has done most of the work for us? Indeed, we did not write a control on a tall building. We already have many finished products and semi-finished products. In many cases, in order to quickly develop a control, you can even make your control directly inherit from specific controls such as textbox and button, and make slight modifications to implement your own functions. If this is not a good thing, you 'd better consider inheriting from the following two classes: system. web. UI. control, system. web. UI. webcontrols. webcontrol: the first class is suitable for controls that are not visualized HTML objects, such as controls that generate <meta> <XML> and other content. The second class is suitable for generating various HTML objects, it has implemented basic style management, HTML Tag generation, and other functions.

The next article will discuss all aspects of control attributes, including the relationship between attributes and the aspx file text of HTML styles, the advanced editing methods of attributes in Vs, And the customization of various interaction methods in IDE.

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.