View Full Version : clear form c# - asp.net
geet40
07-13-2007, 06:07 PM
Hi
after entering the values in the fields of the form i have this add button, which calls a method which on clicking executes sql commands.
After, i click it, i couldnt figure out how to refresh the form by clearing all the values entered and give a message "submitted successfully"
<asp:Button ID="Button1" runat="server" Text="ADD" OnClick = "updateProject_details" />
geet40
07-13-2007, 06:40 PM
I could reset the dropdown list values by using
ID.ClearSelection();
but couldnt figure out for asp text boxes <asp:TextBox >
and rad input <radI:RadTextBox>
Thanks
ASP.NET uses _VIEWSTATE as a hidden field in every form...so that the status of the page can be maintained when posted.
For more information on VIEWSTATE, please visit the following page.
http://msdn2.microsoft.com/en-us/library/ms972976.aspx
There are many ways that you can utilize to clear input fields once the page has been submitted. For example, you can use the "Text" property of an input box and you can set it to be empty. Say you have an input box with an id "UserName", you can set its text to be empty in C# this way.
UserName.Text = "";
Another way is to totally disable the _VIEWSTATE property all together. For example, you can add the following at the top of the page
<%@Page EnableViewState="False" %>
Hope that helps.
Cheers,
Ess
geet40
07-16-2007, 08:35 PM
disabling not working ....
tried
Response.Redirect(Request.path)
and it works...
Thanks for the post.
geet40
07-16-2007, 10:40 PM
As a Note :
What I noticed was when i use
Response.Redirect(Request.path)
it gives error ( seen in debugger)
so went back to clearing fields one at a time
and used empty string to clear the text fields
Thanks
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.