Clear Modal with Button Without Writing Data

0

I have a modal where I use the same for inclusion and change of the data.

I checked that the txtid field is populated. If you have is change, not inclusion.

To fill in the fields the user needs to select the row of the grid, where the id is retrieved 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 the fields all filled in.

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

GridAgenda() is the method that loads the GridView.

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

    
asked by anonymous 14.06.2017 / 20:35

1 answer

0

You can make jquery do this job for you if you do not want to work on the code behind.

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

Now, you will now click on the modal close button to clear the fields:

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

And create a function in jquery to execute all this:

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

Whenever the user clicks the modal close button, the fields are cleared.

    
04.07.2017 / 14:42