DKR DKR - 1 year ago 99
ASP.NET (C#) Question

How to trigger c# method from anchor tag in

I have an anchor tag in .aspx page as below:

<a href="#divrecentQ" runat="server" id="linkdivrecentQ" onclick="alert()" onserverclick="divrecentQInit" aria-controls="divrecentQ" role="tab" data-toggle="tab">Click</a>

I want to tigger c# method using this tag.

protected void divrecentQInit(object sender, EventArgs e)
log.Debug("divrecentQInit is called");


Problem is: divrecentQInit method is not getting called.

Thanks for help.

Not: I do not want to use LinkButton of since it doesnt work very well with bootstrap.

Answer Source

The Method call event(onServerClick) is case-sensitive, Use


instead of


and additionally I would suggest using <asp:LinkButton to achieve the same(you would not need onServerClick in this case, OnClick instead )

<asp:LinkButton runat="server" OnClick="divrecentQInit" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download