Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Frnds,

I have a HyperLink (LogOut) on my webpage when i click this Logout Link it must show.
("Are you sure you want to logout?"). yes / No

Please send me the code.


Thanx.
Posted

protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e)
{
if (e.Item.Text == "Logout")
{
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htmWriter = new HtmlTextWriter(sw);
HyperLink menuLink = new HyperLink();
menuLink.NavigateUrl = e.Item.NavigateUrl;
menuLink.Text = e.Item.Text;
menuLink.Attributes["onClick"] = "return confirm('Are you sure?');";
menuLink.RenderControl(htmWriter);
e.Item.Text = sw.ToString();
}
 
Share this answer
 
Comments
Syed SufiyanUddin 24-Apr-12 6:27am    
where should i write this code ?
mario.a.nunes 2-Oct-13 10:50am    
I have a asp:Menu Bounded to a XmlDataSource
I used this approach (Solution 1)
But I get something funny: It generates an anchor nested in another anchor which produces two menu items: a blank menu item and the correct menu item:
Logout

Can you help me?
Thanks,

Mario Nunes
Pete O'Hanlon 24-Apr-12 6:36am    
In your code behind. You have to put at least some effort in; you can't rely on others to do all your thinking for you.
Pete O'Hanlon 24-Apr-12 6:36am    
Never mind - answered wrong comment.
try this
C#
<asp:linkbutton id="LinkButton2" text="Logout" onclientclick="return confirm("Are you sure you want to Logout");" runat="server" xmlns:asp="#unknown"></asp:linkbutton>
 
Share this answer
 
Comments
AbdulMuheet 24-Apr-12 8:31am    
yes, this should work..
XML
<asp:Button ID="btnLogout" text="Logout" runat="server"
OnClick="DoLogoutFunction();"
OnClientClick="return confirm('Are you sure you want to Logout?')">
</asp:Button>
 
Share this answer
 
Comments
Member 10225360 13-Aug-15 1:44am    
thanks
You can use java script here.

function ConfirmLogout()
{
var confirmLogout=confirm("Are you sure you want to logout?");
if(confirm)
return true;
else
return false;
}
 
Share this answer
 
<a href="your logout URL" onclick="return confirm('Are you sure you want to Logout?')">
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900