If anyone has similar problem or wants to know how it can be done, here is my code.
public static MvcHtmlString Panel(this HtmlHelper html)
{
Panel pnl = new Panel();
pnl.ID = "mainPanel";
pnl.BorderStyle = BorderStyle.Solid;
pnl.BorderWidth = Unit.Pixel(1);
pnl.BorderColor = System.Drawing.Color.Black;
Label lblTitle = new Label();
lblTitle.Text = "Title";
TextBox txtTitle = new TextBox();
txtTitle.ID = "txtTitle";
lblTitle.Attributes.Add("for", "txtTitle");
Label lblMessage = new Label();
lblMessage.Text = "Message";
TextBox txtMessage = new TextBox();
txtMessage.TextMode = TextBoxMode.MultiLine;
txtMessage.ID = "txtMessage";
Label lblDepartment = new Label();
lblDepartment.Text = "Department";
DropDownList lstDepartment = new DropDownList();
lstDepartment.ID = "lstDepartment";
ListItemCollection collection = new ListItemCollection();
collection.Add(new ListItem("Department1"));
collection.Add(new ListItem("Department3"));
collection.Add(new ListItem("NoDepartment"));
lstDepartment.DataSource = collection;
lstDepartment.DataBind();
pnl.Controls.Add(lblTitle);
pnl.Controls.Add(txtTitle);
pnl.Controls.Add(lblMessage);
pnl.Controls.Add(txtMessage);
pnl.Controls.Add(lblDepartment);
pnl.Controls.Add(lstDepartment);
HtmlTextWriter writer = new HtmlTextWriter(new StringWriter());
pnl.RenderControl(writer);
return MvcHtmlString.Create(writer.InnerWriter.ToString());
}
Basically, you use the classes of the web controls you need and you create the HTML. HtmlTextWriter is used to render the things you coded for that purpose.
server side controlsinASP.NET MVC. Don't connectASP.NET web-formswithASP.NET MVC.