1

I have a problem with a webforms application. I have a webforms page that shows a catalog of items. On the presentation code each item is contained in an item template server control which is contained in a Repeater server control. My problem is that when I right click using any browser, it just opens the same page in a new tab though. Can anyone assist with this problem?

Here is what is contained in the repeater and item template control

' onclick='javascript:window.location.href="<%#Path %>?action=detail&<%#Eval("CatalogItemKeyQueryString")%>"'> ' class="img-fluid" style="max-height: 200px; max-width: 100%" /> <%#Eval("ItemName")%>

I tried using the hyperlink control and pointing to the path in the anchor tag I have the item in

' onclick='javascript:window.location.href="<%#Path %>?action=detail&<%#Eval("CatalogItemKeyQueryString")%>"'> ' class="img-fluid" style="max-height: 200px; max-width: 100%" /> <%#Eval("ItemName")%>

The expected result is to right click and open that item in a new tab with the item selected going to its individual page. Actual is that it only opens the exact same thing.

2 Answers2

1

If you add to your site this JavaScript code:

<script>
function openInNewTab(url) {
  var win = window.open(url, '_blank');
  win.focus();
}
</script>

then you can solve your problem with this code:

onclick='openInNewTab("<%#Path %>?action=detail&<%#Eval("CatalogItemKeyQueryString")%>"'

Thanks to @RintoGeorge's answer.

simhumileco
  • 31,877
  • 16
  • 137
  • 115
0

I was able to resolve my problem by putting the line of code <%#Path %>?action=detail&<%#Eval("CatalogItemKeyQueryString")%> in the href attribute of the tag instead of relying on the onclick event handler. Once I did that, when I did a right-click, it opened up the new page.