Why use the native?
1, the purpose of native browser compatibility issues are very few, do not test multi-browsing compatibility. You need to take into account other spam browsers on the market.
2, the performance is not good if you do not consider the first one you can change the way
Directly on the code
. aspx page
<! DOCTYPE html>
Background. CS Code
protected void Page_Load (object sender, EventArgs e) {#region initialization control if (viewstate["Addedc Ontrol "] = = null) {viewstate[" Addedcontrol "] = 1; CreateControl (); } else {int cout = Convert.ToInt32 (viewstate["Addedcontrol"]); for (int i = 0; i < cout; i++) {CreateControl (); }} #endregion if (! IsPostBack) {}}///<summary> Create dynamic Controls for container phbody///</summa ry>//<param name= "index" ></param> public void CreateControl () {Panel PL Body = new Panel (); TextBox txt = new TextBox (); Txt. Text = ""; PLBODY.CONTROLS.ADD (TXT); TextBox txt2 = new TextBox (); Txt2. Text = ""; PLBODY.CONTROLS.ADD (TXT2); TexTbox txt3 = new TextBox (); Txt3. Text = ""; PLBODY.CONTROLS.ADD (TXT3); PHBODY.CONTROLS.ADD (Plbody); }//Get dynamically added control value protected void Btnsave_click (object sender, EventArgs e) {System.Text.Stri Ngbuilder sb = new System.Text.StringBuilder (); for (int i = 0; i < PhBody.Controls.Count; i++) {Control ctrl = Phbody.controls[i]; for (int j = 0; J < Ctrl. Controls.Count; J + +) {if (J <= 3) {TextBox txt = ctrl. CONTROLS[J] as TextBox; if (txt! = null) {sb. Append (txt. Text); }}}} Lbmsg.text = sb. ToString (); }//Add three rows protected void btnAdd_Click (object sender, EventArgs e) {if (viewstate["AdDedcontrol "] = = null) {viewstate[" Addedcontrol "] = 1; } else {int cout = Convert.ToInt32 (viewstate["Addedcontrol"]); viewstate["Addedcontrol"] = cout + 1; } CreateControl (); }//Delete the last row dynamically added control protected void Btndellast_click (object sender, EventArgs e) {int index = Phbody.controls.count-1; PhBody.Controls.RemoveAt (index); if (viewstate["addedcontrol"] = = null) {viewstate["Addedcontrol"] = 0; } else {int cout = Convert.ToInt32 (viewstate["Addedcontrol"]); viewstate["Addedcontrol"] = cout-1; } }
Preview effect
ASP. NET dynamically add server-side controls and submit forms