简体   繁体   中英

Dynamically created href attributes in C#

This is the C# code used to create a link to google

href.Controls.Add(Image);
href.Attributes.Add("href", "www.google.com");
href.Attributes.Add("target", "_blank");
href.Attributes.Add("title", "Click To Follow The Link");

however when I click it, the url it takes me to is this

http://localhost:52647/Mywebsite/www.google.co.za

any ideas on how I make it go straight to google?

Try prefixing it with http://

href.Controls.Add(Image);
href.Attributes.Add("href", "http://www.google.com");
href.Attributes.Add("target", "_blank");
href.Attributes.Add("title", "Click To Follow The Link");

change href.Attributes.Add("href", "www.google.com"); to href.Attributes.Add("href", " http://www.google.com ");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM