Introduction
This post will show you how to add and dynamically create ASP.NET Server Controls and place the controls into an HTML DIV server tag. Create your ASP.NET web application [project] and integrate your required theme(template). As per your requirement, create a web form and design page layout and create a container div with id="myFormContainer" and div as a server control-runat="server". In this div going to add child div, label, textbox, button, etc. controls dynamically.
Create Dynamic ASP.NET Server Control
All controls list retrieved from "Controls" json object (List). You can create a json file and deserialize json object with C# class object, easily create number of controls dynamically with required attributes, e.g., Id, text, etc. You can also try to control list retrieved from database table.
Classes, Methods and Events
Step 1: Create Basic Classes
- public class Control
- {
- public string ID { get; set; }
- public string LabelText { get; set; }
- }
- public class ControlList
- {
- public List<control> Controls { get; set; }
- }
Step 2: Controls List (Get from json Object or Database Table)
- // create the div to add form elements from a controls list
- string json = @"{Controls:[{ID:'UserName', LabelText:'User Name'},
- {ID:'EmailId', LabelText:'Email Address'},{ID:'Password', LabelText:'Password'},
- {ID:'Phone', LabelText:'Phone Number'}]}";
- var controls = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<controllist>(json);
Step 3: Create Method to Bind Controls

Deepak VermaPosted May 2, 2018, 7:27 AM
Great concept...... Thanks for sharing
Ram RatanPosted May 6, 2015, 7:31 AM
Interesting one!!