Clear Modal with Button Without Saving Data

Asked

Viewed 375 times

0

I have a modal where I use it to include and change the data.

I check if the field txtid is completed. If you have a change, it is not included.

To fill in the fields the user needs to select the grid line, where the id is rescued to make the change.

But I need to clear the modal if the user does not make the change.

I created a button that updates the grid, loses the selection and clears the txt, but it opens with all filled fields.

GridAgenda();
GridView1.SelectedIndex = -1;
txtid.Text = "";

GridAgenda() is the method that loads Gridview.

Sometimes it selects and does not change, I click on this button to clear, and click on the register, the modal comes filled with the last selected line.

1 answer

0


You can make jquery do this job for you if you don’t want to work on the Behind code.

Place in the fields to which you want to clear some class for jquery to identify later, e.g.: CssClass="limpar".

Ready, now you will make the click close the modal the action of clearing the fields:

<button type="button" id="btnFechar" class="btn btn-default" data-dismiss="modal">Fechar</button>

And create a function in jquery to run all this:

<script>
     $(function (){
        $("#btnFechar").click(function (){
             $( ".limpar" ).each(function() {
                  $(".limpar").val("");
             });
        });
     });
<script>

Whenever the user clicks on the close button of the modal, the fields will be cleared.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.