In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to understand ASP.NET control development, content concise and easy to understand, absolutely can make your eyes shine, through the detailed introduction of this article I hope you can gain something.
ASP.NET itself provides a lot of controls, provided to us these lazy people use, I think the role of controls here, because we do not want to repeat work, so to create it, this itself is a requirement of the relationship, so learning ASP.NET controls development is very interesting.
It hasn't been published yet, but the code is on the website, so download it and learn it. I've seen the first few chapters of code, and they're all linked together, and the author uses different knowledge to show us the same effect, so it's good to learn it step by step. Although I am not very familiar with ASP.NET control development, I feel that the following points are very important, which is my own summary.
1. To understand the inheritance relationship between controls, *** first look at the System.Web.UI namespace
(1)Control class, a class shared by all controls, you need to look at several protected methods and properties inside, although you can't finish it at once, you will find that these methods are often used later. You can look at its derived classes in MSDN.
(2)HtmlTextWriter class has to understand a class, the main work is we write markup characters and text output
2. rewriting method
(1)Control class must be inherited
(2)Overwrite the Render method of the Control class, this is necessary, because other controls inherit the Control class, so almost all controls have this method
3. Familiarity with metadata
We all know that ASP.NET control attributes are classified on the editor, such as appearance, behavior, layout, etc., each attribute also gives an explanation of simple metadata is to play this role, of course, you can not add, but the use of metadata makes people feel intimate, such as writing
Under [CategoryAttribute("Appearance")] To use metadata, you must refer to the System.ComponentModel naming control. Generally, if you write components, it is impossible not to use such a class library. It is described in detail on MSDN.
I. output string
It's boring to talk too much. Let's practice. First you need to understand HTML. Look at the following code, the effect is to output HTML to the client
The effect is very simple, in fact, has been in the output HTML plus a few properties, we can directly put the code in the App_Code folder, you can automatically compile, of course, you can also create web control library.
Note that to inherit the Control class, override the Render method and output HTML with Write of the HtmlTextWriter class
using controls
(1). Need to register first
(2)Then you can use the label output effect
II. Improvements, adding attributes and metadata
The controls made above may be useless, but they can familiarize you with the steps. The controls above are set very dead, and no attributes are defined. They are not useful. Here are the modifications.
Let's define common properties and then output them so that we can modify the properties of the control
III. Improved again, eliminating HTML output as a string using the Write method
Then we went on to discover that, in addition to defining a few attributes that we needed to modify ourselves, we still had to use a large number of strings to output HTML, and it was easy to type them incorrectly. So the HtmlTextWriter class provides several useful methods instead.
(1)AddStyleAttribute method Adds style attributes to labels
(2)AddAttribute method adds attributes to labels
(3)RenderBeginTag starts to write tag header such as
(4)RenderEndTag writes the tag tail, such as
Here are a few points to note in particular.
1. Because its definition is different from our usual definition, we usually write HTML, is to write the beginning of the tag, and then write the attributes of the tag. For example, we need to define the attributes and styles of the tag first, and then output the tag header.
2. Label head and tail, need one-to-one correspondence. Can be understood as nested relationship.*** The method of understanding is to output code, view the source file, and then combine the original definition of the code.
It is easier to explain by looking at the code. Since CreditCardForm2 has already defined the attributes we need, what we have to do now is to replace the string form with the label form, so we only need to inherit the CreditCardForm2 class and rewrite the Render method.
IV. Consequences of not using view state
Or view state, about view state you can refer to MSDN and related articles
See the following example, CreditCardForm3
if(! IsPostBack) { creditcardform.CardholderNameText="FullName"; creditcardform.CreditCardNoText="CreditCardNo"; creditcardform. Expiration DateText ="Expiration Date"; creditcardform.PaymentMethodText="PaymentOptions"; creditcardform.SubmitButtonText="Send"; The above is how to understand ASP.NET control development. Have you learned knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 250
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.