normally on would use the following :-
aspx page:-
<a ID="a1" href="javascript:void(0);" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener">Link1 </a>
code behind:-
a1.HRef="www.mySite.com/mypage.aspx";
how do u set this HRef attribute in case the anchor tag is within a repeater ?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
For example, in the ItemDatabound event:
protected void rptData_ItemDataBound(object source, RepeaterCommandEventArgs e)
{
HtmlAnchor a1 = (HtmlAnchor)e.Item.FindControl("a1");
a1.HRef = "www.mySite.com/mypage.aspx";
}
Also, don’t forget to put runat="server" on that anchor
<a ID="a1" runat="server" href="javascript:void(0);" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener">Link1 </a>
Method 2
You can do this in the ItemDatabound event.
Check out: http://www.codeguru.com/csharp/.net/net_asp/tutorials/article.php/c12065
Method 3
First you need to make your control server side by putting runat="Server"
<a runat="Server" ID="a1" href="javascript:void(0);" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener">Link1 </a>
protected void rptOuter_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
{
// Find your anchor here
}
}
Method 4
You can do it in the event ItemDatabound of your repeater:
((HtmlAnchor)e.Item.FindControl("a1")).HRef = "www.mySite.com/mypage.aspx";
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0