Gino Perla
Gino Perla

Reputation: 101

Asp .Net element onclick

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

Answers (3)

user4077944
user4077944

Reputation:

Try below :

<a id="logout"         onserverclick="logout_Click"         runat="server">

Upvotes: 3

prog1011
prog1011

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.

  • You can use asp:HtmlAnchor asp tag. It is alternate of HTML <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

StackOverlord
StackOverlord

Reputation: 85

<a runat="server" visible="false" id="logout" onclick="logout_Click()">Log Out</a>

you forgot the parenthesis :D

Upvotes: 0

Related Questions