且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在.aspx C#中将href分配给锚标记

更新时间:2023-02-09 14:14:39

也添加协议。 b $ b

< a href =http://www.Test.com> 


你必须输入完整的地址,从 http://



 <   a     href   =  http://www.Test.com > 测试<   / a  >  





来自代码:

添加 Id 属性和运行at =server到锚标记为

 <   a     id   =  anchorID      runat   =  server > 测试<   / a  >  



href 可以在后面的代码中分配为

 anchorID.Attributes [  href] =   http://www.Test.com; 


aspx page:-

<p class="l">Copyright &copy; 2016 - <a href="www.Test.com">Test</a> &middot; All Rights Reserved.</p>



href="www.Test.com"
click on Test link and I got something like this :- localhost/www.Test.com



Do you know any solutions?

Add the protocol also.

<a href="http://www.Test.com">


you will have to type the full address starts from http://

<a href="http://www.Test.com">Test</a>



from code behind:
add an Id attribute and runat="server" to the anchor tag as

<a id="anchorID"  runat="server">Test</a>


and the href can be assigned in code behind as

anchorID.Attributes["href"] = "http://www.Test.com";