Web Forms Question:
Download Job Interview Questions and Answers PDF
How to create a dynamic control in dot net?
Answers:
Answer #1We can create the dynamic control in the Page_Init() event or Page_Load() event,
protected void Page_Load(object sender, EventArgs e)
{
TextBox dynamicTextBox = new TextBox();
dynamicTextBox.ID = "DynamicTextBox";
dynamicTextBox.AutoPostBack = true;
dynamicTextBox.Text = "InitData";
dynamicTextBox.TextChanged += new EventHandler(dynamicTextBox_TextChanged);
this.Form.Controls.Add(dynamicTextBox);
}
void dynamicTextBox_TextChanged(object sender, EventArgs e)
{
Response.Write("hello");
}
protected void Page_Load(object sender, EventArgs e)
{
TextBox dynamicTextBox = new TextBox();
dynamicTextBox.ID = "DynamicTextBox";
dynamicTextBox.AutoPostBack = true;
dynamicTextBox.Text = "InitData";
dynamicTextBox.TextChanged += new EventHandler(dynamicTextBox_TextChanged);
this.Form.Controls.Add(dynamicTextBox);
}
void dynamicTextBox_TextChanged(object sender, EventArgs e)
{
Response.Write("hello");
}
Answer #2yes
Download Microsoft Web Forms Interview Questions And Answers
PDF
Previous Question | Next Question |
How to access a control inside a UserControl in .net? | How to use QueryString in web forms? |