Clear all fields in ASP.net form

Viewed 72803

Is there an easy way to reset all the fields in a form?

I have around 100 controls in my asp.net form and there are submit and reset buttons.

How do I make all values in the fields null when user hits reset button?

I have a lot of dropdown boxes, textboxes, checkboxes.

7 Answers

Or if you are using Angular.

Add this to your button on the cshtml page:

<input type="button" value="Cancel" id="cancel" ng-click="cancel();" />

And this to your .js file:

$scope.cancel = function () {
    if (!$('form').dirtyForms('isDirty')) {
        $('form').dirtyForms('setClean');
    }
    else {
        $('form').dirtyForms('isDirty', true);
    }
     var that = this;
    var method = that.getUrl('CONTROLLER', 'ACTION', 'id', 'querystring');
    window.location = method;
Related