I'm creating a mobile app using the modal bootstrap, asp.net (aspx). A href link triggers the modal and needs to send to the modal value contained in attribute of type data- * that was created. The goal is to populate a label contained in the modal at the time of its opening and this is not happening. The label fills only after the modal is opened from the 2nd attempt onwards. In the 1st attempt to open the label does not fill. When the modal is closed by clicking the "Yes" (1st attempt) and then reopening the modal, it works; clicking the "No" problem persists. Thank you if you could help.
The href link:
<a href="#" data-toggle="modal" data-target="#myModal" data-marcacao="frase">
The script:
<script type="text/javascript">
$('#myModal').modal({ backdrop: 'static', keyboard: false });
$('#myModal').modal('toggle');
$().ready(function () {
$("a").on("click", function (e) {
e.preventDefault();
$('#lblModalMarcacao').text('Marcação: ' + $(this).attr("data-marcacao"));
});
});
</script>
The modal:
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
</div>
<div class="modal-body">
<div class="wrimagecard-topimage_header">
</div>
<asp:Label ID="lblModalMarcacao" runat="server"></asp:Label>
</div>
<div class="modal-footer">
<button class="btn btn-success btn-md" id="myButton">Sim</button>
<button class="btn btn-danger btn-md" data-dismiss="modal">Não</button>
</div>
</div>
</div>
</div>