Search code examples
c#asp.netanchorhref

Anchor tag not working properly in asp.net


in aspx

 <a id="anchorViewMore" runat="server" > View More</a>

in backend c#

 anchorViewMore.HRef = "www.google.com";

output im getting http://localhost:3180/seoapp%20april%2017%20keyword%20assign%20by%20TL%20-%20backup/www.google.com

i want that href should be only "google.com" and should redirect to that website


Solution

  • Try:

    anchorViewMore.HRef = "http://www.google.com";
    

    If you don't put the 'http://' then it will link relative to the page you are on.

    To make it open in a new window, you need to change the HTML to:

    <a id="anchorViewMore" runat="server" target="_blank"> View More</a>