Creating Form at Runtime.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi.
I want to create forms at runtime in asp.net a don´t know it´s posible to do
this.
And How to do it
 
You can populate a form using an ASPX page by adding controls to a container
(a Panel is a nice container, but even Page can be a container). If this is
what you mean by form (ie, a bunch of controls to fill in), you simply set up
a routine that dynamically creates controls and binds them to a container
(like a Panel, as mentioned above).

private void PaintForm()
{
//assume proper reference to System.Web.UI.WebControls
Label l = new Label();
l.Text = "Name";
Panel1.Controls.Add(l);

TextBox t = new TextBox();
t.ID = "txtName";
t.Width = 50;
t.MaxLength = 25;
Panel1.Controls.Add(t);

//Assume reference to System.Web.UI
LiteralControl lc = new LiteralControl("<br>");
Panel1.Controls.Add(lc);

Button b = new Button();
b.ID = "btnSubmit";
b.Text = "Submit Name";

//Add event handler
b.Click += new EventHandler(this.Button_Click);
}

NOTE: You will have to code in event handlers, like so:

private void Button_Click(object sender, EventArgs e)
{
}

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Back
Top