First, what is the component?
View MSDN, Microsoft is such a definition to component: In .NET Framework, component refers to a class that implements the System.comPonentModel.icomponent interface, or a class directly or indirectly derived from the category that implements IComponent. This is a definition, popular speaking, component is "independently operated software unit", which emphasizes independent operation, which means that the components must have low coupling, high rejection characteristics. Microsoft divides the software into two parts: one is Component, which means that there is a specific function, can operate independently, does not have a Unit of the UI interface; the second is Control, that is, the controls we often say, it means a specific function, Independently operated UI interface unit.
Second, learn the knowledge that the ASP.NET component needs to be mastered
Any master .NET language, it is recommended to use C #, C # is a brand new language, but borrowed from C and Java grammar, and introduced some new concepts, don't get good in programmers.
Understand the running mechanism of IIS and the operation mode of ASP.NET.
Skilled JavaScript, the scripting language power is very good during processing client action, and all custom components are inseparable from JavaScript, and CSS and DHTML are also well-known. No way, they rarely appear alone and always like the collective performance.
Third, the difficulty of component design
This problem doesn't have to ask, maybe you guess a bit, a word: difficult.
You may be aware that when writing ASP.NET applications, rarely works in-depth research on ViewState, because the user object designed by ViewState itself is not an application, but a component designer. If it is not because the client needs, you will not write a large number of JavaScript scripts in the ASP.NET, and in the component design, it is difficult to escape the dry system. More than this, is it designed as a server component? Is our component inherited Control or inherited WebControl or inherited Component? Do you need to customize Attribute in the component? Do you need data binding? How to draw the appearance of the component? How to communicate with IIS? Need Post-back? Many of the problems need to be a component designer - hard to think about it.
So, if you don't want to say anything: Isn't it designed a component? What is difficult? So, I will smile, because I know, you must be joking.
But don't be afraid, "programmers need to explore the spirit!"
Fourth, the choice of base class
If we design a web visible control, and constitute a part of the web page, you can inherit the Control class or the WebControl class. If it is a non-visible control, you can inherit the component, inherit this type of control, not appearing on the page, but appears in Component TRAY. Remember the OpenFileDialog control? This file opens the dialog control is in the Component TRAY control.
If we just enhance the function based on existing controls, then inherit the existing control.
5. Practice realism
Suppose we want to design a component that only allows the user to enter numbers, which naturally should be placed in the client, and the client's verification script can be written:
Function Virty (CTRL)
{
Event.keycode == 13)
Return True
Event.Keycode <48 || Event.Keycode> 57)
Return False;
Else
Return True;
}
script>
HEAD>