What is a custom grouped control
A custom Web Mix control, as its name says, integrates one or more server-side programs and HTML controls in a single control. A custom composite control is functionally similar to a user control. The biggest difference is that it exists only in its own assembly (or shared with other controls), can be placed in a sidebar, and can provide WYSIWYG view of the controls it contains.
On the other hand, custom Web Mix controls are more difficult to create than user controls, because Visual Studio.NET designers do not provide any tools to visualize them, so the question is: Why do you want to replace a user control with a composite control? When you distribute a control to more than one Web program or system, if you use a custom Web Mix control, the situation is much better, and the user control is best used where you don't value reuse, for example, if you're only ready to use controls on your own site, the user control might be a better choice. Basically, between the extra effort you have to create it and the amount of reuse you get from it, make a trade-off; at the same time, because the custom composite control exists only in its own assembly, only one copy is required on each computer, and the user control is placed in the Web assembly, so Must be stored on every web site that uses it.
Create a custom Web Mix control
The steps to create a custom Web Mix control are essentially the same as creating a custom superclass Web control, in this case, SearchControl, the first thing to do is to design the appearance of the control, which, when finished, looks roughly as shown in Figure 1.
Figure 1: Control appearance in the designer
SearchControl, as seen above, consists of three server-side controls (actually four, which will be mentioned later): A Label control, a text box control, and a button. In addition, the tricky part of customizing a web Mix control is that they don't have a good drag-and-drop design tool to support the creation of controls, but they need to be done by hand-writing code in the old way. But it's not exactly true that you don't have to write the server or HTML control code manually, so how do you create a searchcontrol look?
First, write out the definitions of three server-side controls in the SearchControl class:
Label *label;
TextBox *textbox;
Button *button;
Next, create an instance of them in the constructor of the class:
SearchControl::SearchControl()
{
label = new Label();
textbox = new TextBox();
button = new Button();
}
Finally, in the CreateChildControls () method of the class, add them to a collection of child controls for a custom Web Mix control:
void SearchControl::CreateChildControls()
{
Controls->Add(label);
Controls->Add(textbox);
Controls->Add(button);
}
The CreateChildControls () method is a virtual method inherited from the control class, and WebControl is inherited from the control class.
Note that the render () method is not needed here because the server and HTML controls that make up the composite control can draw themselves, so you do not have to consider this method at all, or call the base class in the render () method:
void SearchControl::Render(HtmlTextWriter *output)
{
__super::Render(output);
}