Reputation: 3706
I am creating ASP.NET Hyperlink controls programatically from the code behind like so:
Dim theBritishFlag As New HyperLink()
theBritishFlag.ImageUrl = ConfigurationManager.AppSettings("blobStorageURLHTTP") & "assets/images/winASafari/enFlag.png"
theBritishFlag.NavigateUrl = sectionFunctions.getSectionLink(Request.QueryString("sectionID"), "en", "gb")
Notice that I setting the ImageUrl property of the Hyperlink which means on the page, the hyperlink is rendered like so:
<a href="../../../../fr/fr/s/3499/meet-a-cheetah-home.aspx">
<img src="../assets/images/winASafari/frFlag.png" alt="" />
<!-- this is where the Literal should go--></a>
I would like to add a new ASP Literal like the one below inside of my Hyperlink code above:
Dim theBritishFlagText As New Literal()
theBritishFlagText.Text = "English"
theBritishFlag.Controls.Add(theBritishFlagText)
Does the ASP Hyperlink allow for child controls (such as Literals) to be added to it (inside of its rendered <a>
tags? Because I am finding that this is not working (no text appears inside of the rendered <a>
tags)
I have tagged with VB.NET and C# because this web app uses both.
(And yes I've properly added all controls featured above to the page.)
Upvotes: 1
Views: 1722
Reputation: 14915
You should be able to do it
theBritishFlag .Controls.Add(theBritishFlagText)
Update
I have tested this and it works. Have you added your hyperlink to page's control ??
HyperLink abc = new HyperLink();
abc.NavigateUrl = "www.someurl.com";
Literal xy = new Literal();
xy.Text = "Click Here";
abc.Controls.Add(xy); //add literal to hyperlink control
Image i = new Image();
i.ImageUrl = "http://www.google.co.in/intl/en_ALL/images/logos/images_logo_lg.gif";
abc.Controls.Add(i); //add image
this.Controls.Add(abc); //add hyperlink to page control
Upvotes: 2