Creating simple login page using dynamic controls

Sandhyab
Posted by Sandhyab under ASP.NET category on | Points: 40 | Views : 1224
First In aspx page add panel control
<asp:Panel ID="Panel1" runat="server"></asp:Panel>

In Code Behind:
Label lbl = new Label();
lbl.Text = "LoginForm";
Panel1.Controls.Add(lbl);
Panel1.Controls.Add(new LiteralControl("<br />"));
Panel1.Controls.Add(new LiteralControl("<br />"));
Label lblFirstName = new Label();
lblFirstName.Text = "First Name: ";
lblFirstName.ID = "lblFirstName";
Panel1.Controls.Add(lblFirstName);
TextBox txtFirstName = new TextBox();
txtFirstName.ID = "txtFirstName";
Panel1.Controls.Add(txtFirstName);
Panel1.Controls.Add(new LiteralControl("<br />"));
Panel1.Controls.Add(new LiteralControl("<br />"));
Label lblLastName = new Label();
lblLastName.Text = "Last Name: ";
lblLastName.ID = "lblLastName";
Panel1.Controls.Add(lblLastName);
TextBox txtLastName = new TextBox();
txtLastName.ID = "txtLastName";
Panel1.Controls.Add(txtLastName);
Panel1.Controls.Add(new LiteralControl("<br />"));
Panel1.Controls.Add(new LiteralControl("<br />"));
Label lblPassword = new Label();
lblPassword.Text = "Password: ";
lblPassword.ID = "lblPassword";
Panel1.Controls.Add(lblPassword);
TextBox txtPassword = new TextBox();
txtPassword.ID = "txtPassword";
Panel1.Controls.Add(txtPassword);
Panel1.Controls.Add(new LiteralControl("<br />"));
Panel1.Controls.Add(new LiteralControl("<br />"));
Button btnSave = new Button();
btnSave.ID = "Login";
btnSave.Text = "Login";
Panel1.Controls.Add(btnSave);
lbl.Attributes.Add("onClick", "Login();");


Thanks & Regards

Comments or Responses

Login to post response