Add dynamic controls in web page.

Rajni.Shekhar
Posted by Rajni.Shekhar under ASP.NET category on | Points: 40 | Views : 1161
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
AddDynamicControl();
}
protected override void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
AddDynamicControl();
}
private void AddDynamicControl()
{
Label lblDynamic = new Label();
lblDynamic.Text = "Dynamic Label";
lblDynamic.ID = "lblDynamic";

TextBox txtDynamic = new TextBox();
txtDynamic.Text = "";
txtDynamic.ID = "txtDynamic";

Button btnDynamic = new Button();
btnDynamic.Text = "Dynamic Button";
btnDynamic.ID = "btnDynamic";

btnDynamic.Click += new System.EventHandler(btnDynamic_click);

this.form1.Controls.Add(lblDynamic);
this.form1.Controls.Add(txtDynamic);
this.form1.Controls.Add(new LiteralControl("<BR>"));
this.form1.Controls.Add(new LiteralControl("<BR>"));
this.form1.Controls.Add(btnDynamic);
}
private void btnDynamic_click(Object sender, System.EventArgs e)
{
Response.Write("dynamic button clicked!!!");
}

Comments or Responses

Login to post response