How to clear data from All textbox in a form
-
Hi guys i am developing one website and it is having mane forms. and all those forms have many textboxes. so after inserting data from textbox i want to make all text box clear. for that i dont want to write each and every textbox.text="" so if any one knows other solution please help :(:(
Regards, DJ Rock
-
Hi guys i am developing one website and it is having mane forms. and all those forms have many textboxes. so after inserting data from textbox i want to make all text box clear. for that i dont want to write each and every textbox.text="" so if any one knows other solution please help :(:(
Regards, DJ Rock
I'm not sure, but I think you should play around with viewstate. You can set EnableViewState property of your textboxes to false, or you can set this property to be false for whole page, if you don't need viewstate at all. Or you can override LoadViewState or SaveViewState methods of your Page class. Or you can simply go through all controls and if a control is type of TextBox set its text to ""
foreach(System.Web.UI.Control control in Page.Controls) { SetTextBoxesText(control); } public void SetTextBoxesText(System.Web.UI.Control control) { if (control.GetType() == "System.Web.UI.WebControls.TextBox") { ((System.Web.UI.WebControls.TextBox)control).Text = ""; } foreach (System.Web.UI.Control childControl in control.Controls) { SetTextBoxesText(childControl); } }
Pilo -
I'm not sure, but I think you should play around with viewstate. You can set EnableViewState property of your textboxes to false, or you can set this property to be false for whole page, if you don't need viewstate at all. Or you can override LoadViewState or SaveViewState methods of your Page class. Or you can simply go through all controls and if a control is type of TextBox set its text to ""
foreach(System.Web.UI.Control control in Page.Controls) { SetTextBoxesText(control); } public void SetTextBoxesText(System.Web.UI.Control control) { if (control.GetType() == "System.Web.UI.WebControls.TextBox") { ((System.Web.UI.WebControls.TextBox)control).Text = ""; } foreach (System.Web.UI.Control childControl in control.Controls) { SetTextBoxesText(childControl); } }
Pilo