1: why Web user controls?
2: How to Create web user controls
3: Add properties to Web User Controls
4: add methods to Web User Controls
5. Add events to Web User Controls
6. Web user control application example
Why do we need to customize Web controls?
Combine existing Web controls to implement page Code . We can
Make a web control in some areas.
Any part
How to customize Web controls
Add --> Web user control. The extension is *. ascx.
Add attributes to custom controls
1) the method for adding attributes is the same as that for winform.
2) If this property is dependent on a Web Control of the custom control, you can directly
Add attributes, but if it is a simple attribute, you must use the session object to save
For example:
Public String myproperty
{
Get {return session ["myproperty"]. tostring ();}
Set {session ["myproperty"] = value ;}
}
Add methods to custom controls
Same as winform
Add events to custom controls
A: On the Custom User Control page
1) declare event pointer
Public event eventhandler onclick;
(Event handle type) (pointer name)
In the future, this pointer points to the same type as eventhandler.
Event Process
2) trigger event:
If (this. onclick! = NULL) // indicates that if the pointer has a specific point
{
This. onclick (sender, e); the pointer is used to execute the event it points.
}
B: write in the page_load event of the page using this control:
This. myusercontroll1.onclick + = new eventhandler (longinbutton_onclick );
Note that the corresponding code is automatically generated using the tab key.
Example:
1) create a web user control in the logon box, add the username and password attributes, and add the event that clicks the logon button.
2) create a web control specifically used to display some objects, like a list, with hyperlinks
Like displaying news