IT Community - Software Programming, Web Development and Technical Support

How can we Dynamically create web controls

This is a discussion on How can we Dynamically create web controls within the ASP and ASP.NET Programming forums, part of the Web Development category; Hello, How can we create web controls dynamiclly? How can we change the size of the controls such as height ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 02-15-2008, 02:58 AM
Kirubhananth Kirubhananth is offline
D-Web Programmer
 
Join Date: Feb 2008
Location: My native is Madurai but now in Chennai
Posts: 61
Kirubhananth is on a distinguished road
Send a message via AIM to Kirubhananth Send a message via Skype™ to Kirubhananth
Smile How can we Dynamically create web controls

Hello,

How can we create web controls dynamiclly?
How can we change the size of the controls such as height dynamically?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-15-2008, 04:28 AM
Manikandan.S Manikandan.S is offline
D-Web Trainee
 
Join Date: Feb 2008
Posts: 8
Manikandan.S is on a distinguished road
Default Re: How can we Dynamically create web controls

It is very easy to do it,if you learn DOT NET clearly.
So study it clearly first, then come to do project
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-14-2008, 09:00 PM
poornima poornima is offline
D-Web Sr.Programmer
 
Join Date: Dec 2007
Posts: 189
poornima is on a distinguished road
Smile Re: How can we Dynamically create web controls

Hi,
You can dynamically create web Control..
public class WebForm1 : System.Web.UI.Page
{
// Added by hand; will create instance in OnInit.
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;

override protected void OnInit(EventArgs e)
{
// Create dynamic controls here.
// Use "using System.Web.UI.WebControls;"
TextBox1 = new TextBox();
TextBox1.ID = "TextBox1";
TextBox1.Style["Position"] = "Absolute";
TextBox1.Style["Top"] = "25px";
TextBox1.Style["Left"] = "100px";
form1.Controls.Add(TextBox1);

TextBox2 = new TextBox();
TextBox2.ID = "TextBox2";
TextBox2.Style["Position"] = "Absolute";
TextBox2.Style["Top"] = "60px";
TextBox2.Style["Left"] = "100px";
form1.Controls.Add(TextBox2);
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
base.OnInit(e);
}

This code dynamically creates two TextBox controls, sets their IDs and positions, and then binds them to the Form Controls collection. The code also wires up the TextChanged events of the text boxes to a handler (TextBox_TextChanged).
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
// Set the initial properties for the text boxes.
TextBox1.Text = "TextBox1";
TextBox2.Text = "TextBox2";
}
}
}

Last edited by poornima : 03-14-2008 at 09:14 PM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-14-2008, 10:00 PM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Smile Re: How can we Dynamically create web controls

private void Page_Load(object sender, System.EventArgs e)
{
CheckBox _checkbox = new CheckBox();
_checkbox.ID = "chkDynamicCheckBox";
_checkbox.Text = "This is a dynamically generated checkbox";

Panel1.Controls.Add (_checkbox);
}

(or)
private void Page_Load(object sender, System.EventArgs e)
{
for ( int i = 0; i < 5; i++ )
{
TableRow tr = new TableRow();
// Create column 1
TableCell td1 = new TableCell();
// Create a label control dynamically
Label _label = new Label();
_label.ID = "lbl" + i.ToString();
_label.Text = "Enter Value " + i.ToString();
// Add control to the table cell
td1.Controls.Add(_label);

// Create column 2
TableCell td2 = new TableCell();
TextBox _text = new TextBox();
_text.ID = "txt_" + i.ToString();
// Add control to the table cell
td2.Controls.Add(_text);
// Add cell to the row
tr.Cells.Add(td1);
tr.Cells.Add(td2);
// Add row to the table.
tblDynamic.Rows.Add(tr);
}
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/asp-asp-net-programming/5268-how-can-we-dynamically-create-web-controls.html
Posted By For Type Date
DiscussWeb IT Community - Technical Support and Technology Discussions This thread Refback 02-16-2008 09:57 PM

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET Data Controls Venkat ASP and ASP.NET Programming 133 10-11-2008 08:41 PM
How Create print preview page dynamically in ASP.NET KiruthikaSambandam ASP and ASP.NET Programming 4 03-21-2008 04:42 AM
Code-behind to create node dynamically using XML File or any Stored Procedure poornima ASP and ASP.NET Programming 3 02-14-2008 09:46 PM
WebParts controls S.Vinothkumar ASP and ASP.NET Programming 5 11-16-2007 03:06 AM
Create database object with dynamically S.Vinothkumar C# Programming 6 09-28-2007 11:49 PM


All times are GMT -7. The time now is 07:36 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0