Create controls on WebPart
When we develop related controls, we often need to create some controls and users to interact (such as text input boxes, etc.), I have done one for the WebPart you have edited, summarize, step, in WebPart, the step of creating controls , Is approximately as follows:
1. Statement in the Class of WebPart, declare the controls you want to add, such as adding a button: private button mybutton;
2, rewote CreateChildControls ()
Protected Override Void CreateChildControls ()
{// creation instance
MyButton = new button ();
// Ticket properties of the control
MyButton.Text = "OK";
/ / Specify a click event run function
MyButton.Click = New EventHandler (MyButtonClick);
// Add to control controls.add (myButton);
}
3, performance on WebPart (render)
Protected Override vode RenderWebPart (HTMLTextWriter Output)
{
// First, check if your defined control is created.
EnsureChildControls ();
/ / We can create a table here. When you create a table, create a tag, you must create an end tag, it is recommended to create a set of creations
// Create a table output.renderbegintag (htmlTextWritertag.Table);
// In fact, I think it may be more intuitive with outpurt.write ("").
// Create a row and column and in the corresponding location Render your control
Output.renderbegintag (HTMLTextWritertag.tr);
Output.renderbgeintag (htmlTextwritertag.td);
// This column render button is in this line.
MyButton.RenderControl (Output);
Output.renderendtag ()
Output.renderendtag ()
// Create the end of the table
Output.renderendtag ();
// Finally, don't forget to create a button, click Event Function
Private MyButtonClick (Object Sender, Eventargs E)
{
.........................
}