Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
I have designed menu using
<ul> and <li>
tags and handled onserverclick event, where redirection code is written. This code works fine for normal click. But when I right click on the link and select "Open link in new tab", it opens blank page. So how can I handle this scenario. Any kind of help will nice. Thanks in advance.

Following is the sample code,

<ul class="rounded-corners ">                                                                                <li name="menuSample"><a onserverclick="lnk_clicked" runat="server" href="~/Sample.aspx"                                                                                     title="Sample">Sample</a></li>

Server side code:

protected void lnk_clicked(object sender, EventArgs e)
           strPage = (sender as System.Web.UI.HtmlControls.HtmlAnchor).Title.ToString();
           Response.Redirect((sender as System.Web.UI.HtmlControls.HtmlAnchor).HRef);
Updated 10-Jul-14 3:18am
CHill60 10-Jul-14 7:38am    
Post the code that is causing the problem

By clicking on your ul element "~/Sample.aspx" has to open in newtab

If you want above functionality no need use the javascript function aslo try below code

<ul class="rounded-corners">
<li name="menuSample">
  <a href="~/Sample.aspx" target="_blank">Sample<a>
Share this answer

Not sure why are you again are you handling the server click event here(also are you sure there is an attribute named 'onserverclick' i m not thinking so), because simply setting the 'href' attribute value should work for the anchor tags.

Please remove handler being added as [onserverclick="lnk_clicked"].

Else if it is not working you can try with adding below attribute value like

Hope this will be of help.
Share this answer
Member 10937454 10-Jul-14 9:53am    
Hi thanks for reply. actually onserverclick is present and is working. I am using it because, it has more code regarding permissions and all and I need to handle that before redirecting.
Member 10937454 10-Jul-14 10:01am    
Also target="_blank" isn't working.
see more here w3schools
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