0% found this document useful (0 votes)
29 views1 page

Dynamically Adding TextBox

" / Adding TextBox Dynamically" / Attach the event handler to the button. Add the label and textbox to the panel, then add the panel to the form. Textbox needs a unique id to maintain state information.

Uploaded by

Ali Shaukat
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views1 page

Dynamically Adding TextBox

" / Adding TextBox Dynamically" / Attach the event handler to the button. Add the label and textbox to the panel, then add the panel to the form. Textbox needs a unique id to maintain state information.

Uploaded by

Ali Shaukat
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

"/Adding TextBox Dynamically"/ for (int i = 0; i < TotalNumberAdded; ++i) { AddControls(i + 1); } // Attach the event handler to the

button Button1.Click += new EventHandler(Button1_Click); } void Button1_Click(object sender, EventArgs e) { // Increase the number added and add the new label and textbox TotalNumberAdded++; AddControls(TotalNumberAdded); } private { var var var var var void AddControls(int controlNumber) newPanel = new Panel(); newLabel = new Label(); newLabels = new Label(); newTextbox = new TextBox(); newDropDownList = new DropDownList();

// textbox needs a unique id to maintain state information newTextbox.ID = "TextBox_" + controlNumber; newLabel.Text = "Degree"; newDropDownList.ID = "DropdownList_" + controlNumber; newLabels.Text = "Year"; // add the label and textbox to the panel, then add the panel to the form newPanel.Controls.Add(newLabel); newPanel.Controls.Add(newTextbox); newPanel.Controls.Add(newLabels); newPanel.Controls.Add(newDropDownList); form1.Controls.Add(newPanel); } protected int TotalNumberAdded { get { return (int)(ViewState["TotalNumberAdded"] ?? 0); } set { ViewState["TotalNumberAdded"] = value; } }

You might also like