2

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");
 }

3 Answers 3

3

Try below :

<a id="logout"         onserverclick="logout_Click"         runat="server">
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it works! but the other answer was more exhaustive. Plus he answered before you =) I gave you a big thumb up
2

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");
 }

1 Comment

it was about the OnServerClick, I used onclick instead. Thanks for the explaination. It works now
0
<a runat="server" visible="false" id="logout" onclick="logout_Click()">Log Out</a>

you forgot the parenthesis :D

2 Comments

btw why the visibility is set to false? maybe that's why you can't see it?
oh well it's a normal website, I have a login label, I click it and it goes to "/Login.aspx", then I login, so the loginlable.Visible="false"; and logout.Visible="true"; cause I'm already logged in. Now I have to associate logout with a C# method. Anyway, when I log in the label becomes visible. Also if it's invisible you're still able to see it. hmm :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.