Click here to Skip to main content
15,922,584 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to set all controls empty after submitting form
Posted
Comments
sandeep_kumar 28-Jan-14 5:31am    
Do you want code in javascript or server side?

Create an method for Assign empty string in each control that you want to empty and call that method after submit button click
 
Share this answer
 
Hello,
Approach 1-
Step1:
Create the following function in aspx.cs
C#
private void ClearControls(ControlCollection ctrls)
       {
           foreach (Control ctrl in ctrls)
           {
               if (ctrl is TextBox)
                   ((TextBox)ctrl).Text = string.Empty;
               else if (ctrl is DropDownList)
                   ((DropDownList)ctrl).ClearSelection();

               ClearControls(ctrl.Controls);
           }
       }


Step2: Call the ClearControls function in the Submit button click event like this
C#
ClearControls(Page.Controls);


Approach2-

Use this code inside button click event:
C#
Form.Controls.Clear();


Approach3-
Use this code inside button click event:
C#
Page.Response.Redirect(Page.Request.Url.RawUrl)


Approach4-
Use this code to redirect to the same page
C#
Response.Redirect(Request.Url.PathAndQuery, true);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900