1

I have an Advanced Find Form that contains a few asp:textbox controls as well as asp:dropdownlist controls. When I hit my reset button, it works well in clearing or resetting my textboxes and dropdownlists. However, when the user clicks "Go" to submit the search query and a grid is shown with the results, the reset button no longer works.

Here's my input button:

<input type="reset" value="Clear All" />

EDIT:

Please note that I need to reset the fields to "Default Values" and also I need to be doing without a postback, to be doing it on client side

user3340627
  • 3,023
  • 6
  • 35
  • 80

3 Answers3

1

Have you try with normal button :

<asp:Button ID="txtResetbtn" runat="server" OnClick="txtResetbtn_Click" />

protected void txtResetbtn_Click(object sender, EventArgs e)
    {
      TextBox1.Text = string.Empty;
    }

I think the problem is that HTML button don't reset after a postback

Or you can try to do this in the :

<asp:Button runat="server" ID="reBt" Text="Reset" 
OnClientClick="this.form.reset();return false;" 
CausesValidation="false" />

From : Reset a page in ASP.NET without postback

That link can help you too : Is there an easy way to clear an ASP.NET form?

Community
  • 1
  • 1
Nikolay
  • 329
  • 1
  • 7
1

The input type "reset" does not clear the form, it resets the form to its default values. To clear the form after submitting, you'll have to use javascript to set all values to empty.

Edit:

Since you're using asp.net, you could also use an <asp:button /> to call a method that clears the values of each control in the form.

Edit 2:

If you need to keep this function client-side, you'll have to use Javascript. Also, I think it's important to make a distiction between resetting to a default value (what the "reset" input type does) and clearing the values in a form, even after a submit. To do the later on the client side, you'll have to write a little javascript.

TenneC
  • 48
  • 7
  • I think i was mistaken in describing what i need, yes i do need a reset to defaults, also without a postback. I will update my question with these details – user3340627 Jul 08 '15 at 14:40
0

I managed to workaround the problem. As TenneC and Nikolay have mentioned in previous answers, I used an ASP.Net button but I've performed the reset function using jquery as follows:

  $(document).ready(function(){
            $("#BtnClear").click(function () {
                $('#FillForm input').val(function () {
                    return this.defaultValue;
                });

                $('#DDLId1').val(function () {
                    return this.defaultValue;
                });

                $('#DDLId2').val(function () {
                    return this.defaultValue;
                });

            });
            });
user3340627
  • 3,023
  • 6
  • 35
  • 80