Hi, I've got a question for you,
I've got three buttons, i want the ID of the last clicked button in my code behind.
This is actually don't work:
$(function () {
$('.btn').click(function () {
$('.btn').attr('class', 'btn btn-default');
$(this).attr('class', 'btn btn-primary');
$("#<%=hfCb.ClientID%>").val($(this).attr('ID'));
});
});
<button runat="server" id="btnFiltreLeft" type="button" class="btn btn-default" önserverclick="btnFiltre_Click">Réceptionnés</button>
<button runat="server" id="btnFiltreCenter" type="button" class="btn btn-default" önserverclick="btnFiltre_Click">Validés</button>
<button runat="server" id="btnFiltreRight" type="button" class="btn btn-default" önserverclick="btnFiltre_Click">Tous</button>
btnFiltre_Click must be called here. In console I can see that the hidden field has the correct value but not in my code behind.
Protected Sub btnFiltre_Click(sender As Object, e As EventArgs)
Debug.WriteLine(hfCb.Value)
End Sub
I've got a workaround, if I remove all the
onserverclick="btnFiltre_Click"
and do this in the JS
$(function () {
$('.btn').click(function () {
$('.btn').attr('class', 'btn btn-default');
$(this).attr('class', 'btn btn-primary');
$("#<%=hfCb.ClientID%>").val($(this).attr('ID'));
__doPostBack('ctl00$ContentPlaceHolder1$btnFiltre', "");
});
});
I got the correct value in the code behind. But I want to know why I wasn't, is it due to the lyfecycle or what?