Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
I have designed menu using
HTML
<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,

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



Server side code:

C#
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);
       }
Posted
Updated 10-Jul-14 3:18am
v4
Comments
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

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

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
HTML
target="_blank" 


Hope this will be of help.
 
Share this answer
 
Comments
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
 
v2

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