I need to read the href from a LiteralControl
and add some attributes to it:
Markup;
<a id="aMyAnchor" runat="server" href="bob.com">click me</a>
Here's what I tried:
string url= "bob.com";
var myAnchor = divLinkContainer.Controls
.Cast<LiteralControl>()
.Where(a => a.Attributes["href"]
.Contains(url)).First();
However, LiteralControl
does not have an attributes property...
NOTE: I know I can access the link directly via its id, but that's just because I made the example code simple.
EDIT:
This:
string url= "bob.com";
var myAnchor = divLinkContainer.Controls
.Cast<HtmlAnchor>()
.Where(a => a.HRef
.Contains(url)).First();
results in this:
Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.HtmlControls.HtmlAnchor'.