Reputation: 3979
I having difficulty in meeting add an event click on a div tag with runat = "server". This works perfectly on IE but not on chrome, mozilla .. Search error :-)
Here is the code I tried
JAVASCRIPT:
function showAlertAnomalie() {
alert("Handler test");
}
ASP:
<div id="btn_alert_anomalie" class="alertAnomalieClass" runat="server" onclick="showAlertAnomalie" >
<asp:Label runat="server" Text="Alert annomaly" Font-Bold="true" Font-Size="12" ForeColor="White" style="cursor:pointer;"></asp:Label>
</div>
I ave also try this but not work.. :
$("#btn_alert_anomalie").click(function () {
alert("Handler test");
});
Upvotes: 2
Views: 1012
Reputation:
An inline onclick
attribute is supposed to contain the body of the click handler, not the name of it. Try this:
onclick="showAlertAnomalie();"
Here is a demonstration: http://jsfiddle.net/UgcEQ/
The problem was that doing this:
onclick="showAlertAnomalie"
is equivalent to doing this:
var btn = document.getElementById('btn_alert_anomalie');
btn.onclick = function(){
showAlertAnomalie
}
which doesn't really do anything.
Upvotes: 2
Reputation: 9370
Try :
$('#<%=btn_alert_anomalie.ClientID%>').click(function () {
alert("Handler test");
});
Upvotes: 1