This
blog post will provide you how to Add and Create Dynamically ASP.NET
Server Controls and place the controls in to an html DIV server Tag.
Create your ap.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 conatainer 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" josn object (List).
You can create a json file and Deserialize json object with c# class
object, easily create number of controls dynamic with required
attributes eg, Id, text etc.. You can also try to controls list
retrieved from database table.
Code
: 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
///
<summary>
///
Create & Add Contols to the container div
///
</summary>
///
<param
name="controls"></param>
private
void
AddControls(ControlList
controls)
{
foreach
(var
control in
controls.Controls)
{
//Create
Group Container Div
HtmlGenericControl
div = new
HtmlGenericControl("div");
div.Attributes.Add("class",
"form-group");
//
create label and add to the div
div.Controls.Add(new
Label()
{ Text = control.LabelText, AssociatedControlID = control.ID,
CssClass = "col-md-2
control-label"
});
//create
the div to add controls eg. textbox, checkbox etc.
HtmlGenericControl
divInner = new
HtmlGenericControl("div");
divInner.Attributes.Add("class",
"col-md-10");
//Create
TextBox
divInner.Controls.Add(new
TextBox()
{ ID = control.ID, CssClass = "form-control"
});
//Create
Validator
divInner.Controls.Add(new
RequiredFieldValidator()
{ ControlToValidate = control.ID, CssClass = "text-danger",
ErrorMessage = "The
user name field is required."
});
div.Controls.Add(divInner);
Container.Controls.Add(div);
}
//create
button with event and add to the div
var
button = new
Button
{ ID = "btnClick",
Text = "Create"
};
button.Click
+= btnClick_OnClick;
Container.Controls.Add(button);
}
Step
4: Call CreateControl() method on OnInit event
///
<summary>
///
Load Controls on OnInit event
///
</summary>
///
<param
name="e"></param>
override
protected
void
OnInit(EventArgs
e)
{
//
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);
AddControls(controls);
//
Method with controls list param
}
HTML
Code
<html
xmlns="http://www.w3.org/1999/xhtml">
<head
runat="server">
<title>DEMO
- Create Dynamic ASP.NET Server Control</title>
<link
href="css/Site.css"
rel="stylesheet"
/>
<link
href="css/bootstrap.min.css"
rel="stylesheet"
/>
<link
href="css/bootstrap.css"
rel="stylesheet"
/>
</head>
<body>
<div
class="container
body-content">
<form
id="form1"
runat="server">
<div>
<h3>DEMO
- Create Dynamic ASP.NET Server Control</h3>
<div
class="row">
<div
class="col-md-8">
<h4><u>User
Register</u></h4>
<section
id="Form">
<div
id="Container"
runat="server"
class="form-horizontal">
<span
class="menu-icon"><i
class="fa
fa-globe"></i></span>
</div>
</section>
</div>
</div>
</div>
</form>
</div>
</body>
</html>
Thanks
ReplyDeleteThanks... sure
ReplyDelete
ReplyDeleteGreetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.
AWS Training in Bangalore | Amazon Web Services Training in Bangalore
Amazon Web Services Training in Pune | Best AWS Training in Pune
AWS Online Training | Online AWS Certification Course - Gangboard
This is quite educational arrange. It has famous breeding about what I rarity to vouch. Colossal proverb. This trumpet is a famous tone to nab to troths. Congratulations on a career well achieved. This arrange is synchronous s informative impolites festivity to pity. I appreciated what you ok extremely here
ReplyDeleteClick here:
angularjs training in btm
Click here:
angularjs training in rajajinagar
All the points you described so beautiful. Every time i read your i blog and i am so surprised that how you can write so well.
ReplyDeleteBlueprism training in Chennai
Blueprism training in Bangalore
Blueprism training in Pune
Blueprism online training
All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
ReplyDeleteData Science with Python training in chenni
Data Science training in chennai
Data science training in velachery
Data science training in tambaram
Data Science training in OMR
Data Science training in anna nagar
Data Science training in chennai
Data science training in Bangalore
Thanks for the good words! Really appreciated. Great post. I’ve been commenting a lot on a few blogs recently, but I hadn’t thought about my approach until you brought it up.
ReplyDeletejava training in tambaram | java training in velachery
java training in omr | oracle training in chennai
java training in annanagar | java training in chennai
Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging
ReplyDeleteDevops training in velachery
Devops training in annanagar
I really appreciate this post. I’ve been looking all over for this! Thank goodness I found it on Bing. You’ve made my day! Thx again!
ReplyDeletepython training in pune
python online training
python training in OMR
Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic.
ReplyDeleteBlueprism training institute in Chennai
Blueprism online training
Blue Prism Training Course in Pune
Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
ReplyDeleteAWS Interview Questions And Answers
AWS Training in Bangalore | Amazon Web Services Training in Bangalore
AWS Training in Pune | Best Amazon Web Services Training in Pune
Amazon Web Services Training in Pune | Best AWS Training in Pune
AWS Online Training | Online AWS Certification Course - Gangboard
Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.
ReplyDeleteDevops training in sholinganallur
Devops training in velachery
Devops training in annanagar
Devops training in tambaram
Thanks for such a great article here. I was searching for something like this for quite a long time and at last I’ve found it on your blog. It was definitely interesting for me to read about their market situation nowadays.
ReplyDeletejava training in chennai | java training in bangalore
java interview questions and answers | core java interview questions and answers
Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
ReplyDeleterpa training in velachery| rpa training in tambaram |rpa training in sholinganallur | rpa training in annanagar| rpa training in kalyannagar
Awesome article. It is so detailed and well formatted that i enjoyed reading it as well as get some new information too.
ReplyDeleteJava training in Indira nagar | Java training in Rajaji nagar
Java training in Marathahalli | Java training in Btm layout
Wonderful bloggers like yourself who would positively reply encouraged me to be more open and engaging in commenting.So know it's helpful.
ReplyDeleteData Science Training in Indira nagar | Data Science Training in Electronic city
Python Training in Kalyan nagar | Data Science training in Indira nagar
Data Science Training in Marathahalli | Data Science Training in BTM Layout
It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
ReplyDeleteangularjs Training in bangalore
angularjs Training in bangalore
angularjs Training in chennai
python training in pune
python training institute in chennai
python training in Bangalore
Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me.
ReplyDeletedevops online training
aws online training
data science with python online training
data science online training
rpa online training
Thank you for allowing me to read it, welcome to the next in a recent article. And thanks for sharing the nice article, keep posting or updating news article.
ReplyDeletedevops online training
aws online training
data science with python online training
data science online training
rpa online training
indeed, I’m just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I’ve had.
ReplyDeleteSOFTWARE TRAINING IN CHENNAI
POWERBI TRAINING IN CHENNAI
CCNA TRAINING IN CHENNAI
ANDROID TRAINING IN CHENNAI
Wow, what an awesome spot to spend hours and hours! It's beautiful and I'm also surprised that you had it all to yourselves! Kindly visit us @ Best HIV Treatment in India | Top HIV Hospital in India | HIV AIDS Treatment in Mumbai
ReplyDeleteHIV Specialist in Bangalore | HIV Positive Treatment in India | Medicine for AIDS in India
Nice blog, it's so knowledgeable, informative, and good looking site. I appreciate your hard work. Good job. Thank you for this wonderful sharing with us. Keep Sharing.
ReplyDeleteKindly visit us @ 100% Job Placement | Best Colleges for Computer Engineering
Biomedical Engineering Colleges in Coimbatore | Best Biotechnology Colleges in Tamilnadu
Biotechnology Colleges in Coimbatore | Biotechnology Courses in Coimbatore
Best MCA Colleges in Tamilnadu | Best MBA Colleges in Coimbatore
Engineering Courses in Tamilnadu | Engg Colleges in Coimbatore
very nice blogger ..............!
ReplyDeleteinplant training in chennai
inplant training in chennai for it.php
panama web hosting
syria hosting
services hosting
afghanistan shared web hosting
andorra web hosting
belarus web hosting
brunei darussalam hosting
inplant training in chennai
nice..
ReplyDeleteinplant training in chennai
inplant training in chennai
inplant training in chennai for it
hosting
india hosting
india web hosting
iran web hosting
technology 11 great image sites like imgur hosting
final year project dotnet server hacking what is web hosting
macao web hosting
very nice....
ReplyDeleteinplant training in chennai
inplant training in chennai
inplant training in chennai for it
namibia web hosting
norway web hosting
rwanda web hosting
spain hosting
turkey web hosting
venezuela hosting
vietnam shared web hosting
Nice blog...
ReplyDeleteBest Travels in Madurai | Tours and Travels in Madurai | Best tour operators in Madurai
I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.
ReplyDeleteSalesforce Training | Online Course | Certification in chennai | Salesforce Training | Online Course | Certification in bangalore | Salesforce Training | Online Course | Certification in hyderabad | Salesforce Training | Online Course | Certification in pune
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.thanks a lot.
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
ReplyDeleteHi, Very nice article. I hope you will publish again such type of post. Thank you!
Corporate gifts ideas | Corporate gifts
Corporate gifts singapore | Corporate gifts in singapore
Promotional gifts singapore | Corporate gifts wholesale Singapore
leather corporate gifts singapore | t shirts supplier singapore
thumb drive supplier singapore | business card holder singapore
corporate gifts supplier | customized corporate gifts singapore
corporate gifts supplier singapore
Very interesting post.Keep posting.
ReplyDeleteJava training in Chennai
Java training in Bangalore
Java training in Hyderabad
Java Training in Coimbatore
Java Online Training
Awesome blog. Thanks for sharing such a worthy information....
ReplyDeleteIELTS Coaching in Pune
IELTS Coaching in Gurgaon
Some may stag in Interviews!!! OOPS!! More than 50% of students do this in their career. Instead, do Hadoop Training in Chennai at Infycle. Those students can easily clear this Interview session because more than 5 times at INFYCLE practicing mock-interview sessions, Hence students are Getting out of their interview fear.
ReplyDeleteThis post is so interactive and informative.keep update more information...
ReplyDeleteSalesforce Training in Tambaram
Salesforce Training in Chennai
Very nice post... thanks for sharing such a nice post
ReplyDeleteJapanese Classes in Chennai | Japanese Language Course in Chennai
This comment has been removed by the author.
ReplyDelete