0

I've got this code, using Target="_blank" which should open the "NavigateURL" in a new tab:

<div class="row">
    <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="https://www.amazon.com/Rebel-Cause-Twains- 
        Hidden-Memoirs/dp/107331071X/garrphotgall-20">
        <asp:image runat="server" ImageUrl="Images\RWAC_BothCovers.jpg" 
            style="width:144px;height:120px;margin-left: 60px;" /><br />
        <asp:Label runat="server" Target="_blank"></asp:Label>
    </asp:HyperLink>
</div>

...but it doesn't; is this because it is the "test" version of my site, running from Visual Studio (IIS Express (Google Chrome))? Or would it also not work right in the "real world"? If so, what can I do to fix it?

I don't know why the Label needs to be there (I copied the idea from elsewhere), but even when I added the Target="_blank" within the main part of the asp:Hyperlink (outside the asp:Label) -- whether I take the label completely out or not -- it works the same (it doesn't work right, or as I expect it to, that is).

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • 1
    Does this answer your question? [How do I use Target=\_blank on a response.redirect?](https://stackoverflow.com/questions/8994285/how-do-i-use-target-blank-on-a-response-redirect) – MaxiGui Oct 07 '20 at 09:00
  • Sort of; but I don't want to use javascript. I still can't get the Target=_blank to work – B. Clay Shannon-B. Crow Raven Oct 07 '20 at 18:00
  • 1
    Quote from question in comment above: « If I understand this correctly, you want to be able to open the redirected URL in a new window, but presumably retain the original target in the same window. Unfortunately you cannot do this, because the redirect is served by the server and not browser. You could potentially redirect to a page that contained some script that opened a new window based on a URL querystring parameter. But this would open yourself up to XSS if your not careful. » – MaxiGui Oct 07 '20 at 19:40
  • 1
    why is there a target on a label and not on the link? – epascarello Oct 13 '20 at 18:10
  • I didn't see your comment when I answered below. – B. Clay Shannon-B. Crow Raven Oct 13 '20 at 18:45

1 Answers1

0

The problem should have been obvious: the Target="_blank" was on the wrong element. In fact, I don't need a Label at all.

Putting the directive in the right place (on the asp:HyperLink):

<div class="row" style="justify-content:center;padding-top: 8px;padding-bottom: 4px;">
    <asp:HyperLink ID="HyperLink10" runat="server" Target="_blank" 
            NavigateUrl="https://www.amazon.com/Adventures-Screen-Trade-William- 
            Goldman-ebook/dp/B007Z7UDF8/garrphotgall-20">
        <asp:image runat="server" 
            ImageUrl="Images\Goldman_AdventuresInTheScreenTrade.jpg" 
            class="img-fluid" style="width:144px;height:144px;border: 2px solid blue;" 
            />
    </asp:HyperLink>
</div>

...causes it to work just fine - clicking the image opens up a new tab.

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862