Reputation: 101
I'd need this to work. I have to associate to the following line of code an onclick event. I don't have a button and I can't use one. I want to use this list item to make the onclick method work
<li><a runat="server" visible="false" id="logout" onclick="logout_Click">Log Out</a></li>
C# code:
protected void logout_Click(object sender, EventArgs e)
{
Session.Clear();
Response.Redirect("~/Default.aspx");
}
Upvotes: 2
Views: 3175
Reputation:
Try below :
<a id="logout" onserverclick="logout_Click" runat="server">
Upvotes: 3
Reputation: 3495
You need to explore your self about Client Side Event
and Sever Side Event
first.
<a>
anchor tag is an HTML tag and for server-side call - you need PageMethod
or ajax call
.
<a>
tag.HTML Code -
<li><asp:HtmlAnchor OnServerClick="logout_Click" /></li>
C# Code -
protected void logout_Click(object sender, EventArgs e)
{
Session.Clear();
Response.Redirect("~/Default.aspx");
}
Upvotes: 2
Reputation: 85
<a runat="server" visible="false" id="logout" onclick="logout_Click()">Log Out</a>
you forgot the parenthesis :D
Upvotes: 0