I am currently in the process of developing an ASP.NET application that requires the dynamic creation of "TextBox" and "DropdownList" controls. Here is the method I have been using to create "TextBox" controls:
private void CreateTextBox(string id, string labelName)
{
Label lbl = new Label();
lbl.Text = labelName;
pnlDynamicControls.Controls.Add(lbl);
TextBox txt = new TextBox();
txt.ID = id;
pnlDynamicControls.Controls.Add(txt);
}
As part of my development, I am utilizing the bootstrap theme for my web pages. Below is an example of a styled "Textbox":
<div class="form-group">
<label class="col-sm-2 control-label">Document Base:</label>
<div class="col-sm-4">
<asp:TextBox ID="txtName" runat="server" CssClass="form-control"></asp:TextBox >
</div>
In order to maintain consistency, I would like this style to be applied to the dynamically created "TextBox" controls along with the surrounding "div" tag. Can anyone assist me in achieving this?
The technologies I am working with include ASP.NET, C#, Bootstrap 3, and Visual Studio 2017.
Update: The following image illustrates how the control looks once the CssClass has been added: https://i.sstatic.net/dOT1U.png
I am aiming for it to resemble the following design: https://i.sstatic.net/VK6SM.png