Reputation: 107
I'm trying to call c# event from javascript function. I tried this:
<script type="text/javascript">
function LikeClick() {
document.getElementById('<%=Helper.ClientID %>').click();
}
</script>
<asp:Button ID="Helper" runat="server" OnClick="Helper_Click" />
But it doesn't trigger the c# event.
Upvotes: 1
Views: 929
Reputation: 1433
I believe a <asp:Button>
will natively post the form back without a client side event handler. You need a control that does not natively post back but instead uses a client side click handler to call the __doPostBack()
function.
Change
<asp:Button ID="Helper" runat="server" OnClick="Helper_Click" />
to this
<asp:LinkButton ID="Helper" runat="server" OnClick="Helper_Click" />
Upvotes: 2