Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    clear form c# - asp.net

    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"

    Code:
    <asp:Button ID="Button1" runat="server" Text="ADD" OnClick = "updateProject_details"  />

  • #2
    New Coder
    Join Date
    Jun 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    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

  • #4
    New Coder
    Join Date
    Jun 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    disabling not working ....

    tried

    Response.Redirect(Request.path)
    and it works...

    Thanks for the post.

  • #5
    New Coder
    Join Date
    Jun 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •