http://www.singingeels.com/Articles/Dynamically_Created_Controls_in_ASPNET.aspx
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
private TextBox [ ] m_dynamicTextBoxes; //this is class variable
public string msg = "";
protected override void OnInit ( EventArgs e )
{ //HUOMI THIS FIRST
base.OnInit ( e );
c_button.Click += new EventHandler ( ButtonClick ); //add the event handelr for all textboxes !!!
m_dynamicTextBoxes = new TextBox [ 5 ]; //populate the array of TextBoxes
for (int i = 0; i < 5; i++)
{
TextBox textBox = new TextBox ( );
textBox.ID = "c_textBox" + i.ToString ( );
c_placeholder.Controls.Add ( textBox );
m_dynamicTextBoxes [ i ] = textBox;
} //eof for
} //eof OnInit
protected void ButtonClick ( object sender, EventArgs e )
{
GUIBuilder.GenerateEmptyForm ( ref msg , ref sender , ref e , ref m_dynamicTextBoxes, ref c_label );
} //eof ButtonClick
protected void Page_Load(object sender, EventArgs e)
{
} //eof Page_Load
} //eof class Page
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
///
/// Take the logic of building out from the web page class
///
public class GUIBuilder
{
public GUIBuilder()
{
//
// TODO: Add constructor logic here
//
} //eof cons
public static void GenerateEmptyForm ( ref string msg , ref object sender , EventArgs e ,
ref TextBox [ ] m_dynamicTextBoxes , ref Label c_label )
{
foreach (TextBox textBox in m_dynamicTextBoxes)
{
c_label.Text += "the text was " + textBox.Text + " -- ";
}
} //eof GenerateEmpty Form
} //eof GUIBuilder
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!