Click here to Skip to main content
15,887,283 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am working on a asp.net web application where we have search page. On this search page we have around 37 search filter control. All Input controls are different types like some are text boxes, Dropdownlist (which filled from Database on page load), Radio buttons and check box list.
On right side of page we are showing results of that search with the help of Jquery and Ajax. Now I create a .ascx User Control for left side Search filter and put all the Search filter controls in that user control. This page works fine for me the only issue is I have on Reset Search button on that page (i.e. Inside my ascx control) and I have to clear all the search filter controls value on that buttons click event( remember I don't want to reload my page so i use Jquery).
On solution for is, i have to write code for all 37 controls to reset its value to default.
Is there any trick or idea to reset or reload my user control from Jquery without refreshing page.

Note : Remember I can't put Update panel on aspx page for some reason.

Please give me any idea.
Posted
Comments
Dholakiya Ankit 8-Aug-13 8:11am    
http://scottonwriting.net/sowblog/archive/2010/12/23/resetting-form-field-values-in-an-asp-net-webform.aspx

here are the two approches which will give you more idea

Good question. I tried this some time back but left in middle and went ahead with another approach.

Btw, this link might help:

http://stackoverflow.com/questions/8386766/refresh-user-control-with-jquery[^]
 
Share this answer
 
Comments
NileshKRathod 14-Aug-13 7:59am    
Thanks but this is not a pure Jquery based solution.
you can try like

to clear all textBoxes in your page
JavaScript
$('input[type=text]).each(function(){
    $(this).val('');
});


to clear all textBoxes in your given div or some other container

JavaScript
$('#divContainer').find('input[type=text]).each(function(){
    $(this).val('');
});



And so on..

you can find how to clear other controls.

Hope this helps.
 
Share this answer
 
Comments
NileshKRathod 14-Aug-13 8:01am    
Sorry but this is the last way to achieve functionality. I want a short method or plugin in Jquery.
Thanks to all for your suggestions. I found a short and simple way on google which is more easy and convenient for this.


You can use input type selector for minimal code ie. $(':input') will select all text box field. If you want to clear all controls on current form I have written a small plugin you can use it:

JavaScript
$.fn.clearForm = function () {
    return this.each(function () {
        var type = this.type, tag = this.tagName.toLowerCase();
        if (tag == 'form' || tag == 'div') 
            return $(':input', this).clearForm();
        if (type == 'text' || type == 'password' || tag == 'textarea')
            this.value = '';
        else if (type == 'checkbox' || type == 'radio')
            this.checked = false;
        else if (tag == 'select')
            this.selectedIndex = -1;
    });
};
Usage:
 
$('#divId').clearForm();
$('.div_class').clearForm();
$('form').clearForm();


Source : Click Here
 
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