Why does "_Blank" not cause the URL to open in a new Browser Window?

241 views Asked by At

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).

1

There are 1 answers

0
B. Clay Shannon-B. Crow Raven On

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.