Solved

create server control dynamically in asp.net

Posted on 2013-12-13
1
333 Views
Last Modified: 2013-12-16
I have multiple forms and each form has its own page. I want to combine them to a single page and have server control gets create dynamically. Should I store each control id, name in sql? When page loads, how to it bind each control to value from db?  How should I go about doing something like this?  It could be done!
0
Comment
Question by:VBdotnet2005
1 Comment
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 500 total points
ID: 39718450
Controls are nothing but class in .NET.

Say for example, if you want to adde a text box dynamically in to a server control C, you could follow below code.

TextBox txtBox = new TextBox();

txtBox.ID ="txtOption" + Rand().ToString();
txtBox.Width= Unit.Pixel(45);
txtBox.MaxLength = 2;

c.Controls.Add(txtBox);

//Then finally the server control could be added to page.

Page.Controls.Add(c);

Please do refer

 http://www.codeproject.com/Articles/14450/Dynamic-creation-of-ASP-NET-server-controls-on-fly

http://couldbedone.blogspot.in/2007/06/dynamically-created-controls-in-aspnet.html

http://www.dreamincode.net/forums/topic/328007-add-aspnet-controls-dynamically/

for more information.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now