Adding hyperlinks to labels?

R

Rob Meade

Hi all,

I've tried to add a hyperlink object inside a label object and its not
having any of it...any ideas?

Code below..

' Declare variables
Dim Link As Hyperlink

' Create a new hyperlink instance
Link = New HyperLink

' Set the properties for our hyperlink
Link.NavigateUrl = "../Default.aspx"
Link.CssClass = "horizontalNavigationText"
Link.ToolTip = "Home"

' Add our home hyperlink
lblNavigation.Controls.Add(Link)

After this I then add some text to it...

lblNavigation.Text = " \ Weddings"

The end result should look like this:

Home \ Weddings

with the Home being a hyperlink back to default.aspx etc

I had this previously by setting the text to equal all of the html needed,
ie

lblNavigation.Text = "<a href=""default.aspx"" title=""Home"">Home</a>"

which work but I guessed it wasn't really the best way to do it (typical
that that worked and the new way doesnt!)..

I've added the hyperlinks like the new way above within table cells before
and they've been fine - not tried a label before - can it be done?

Any help appreciated,

Regards

Rob
 
R

Rob Meade

hmmm...seems I missed the

Link.Text = "Home"


Now this makes more sense why it isn't appearing as expected - if I rem out
the line that adds the text , ie " / Weddings" then I get the hyperlink, if
I swap that around I get the text but with no hyperlink - I guess I am
writing the .Text of this object which ever way I do it so I will need to
concatenate the two to make this work - sound about right?

Regards

Rob
 
R

Rob Meade

Hmmm...that concatenation didnt work...I still get one or the other
depending on which code is used :(

Anyone got any ideas? Going back to the html creation in a string then
dumping it out seems messy now ...
 
R

Rob Meade

woooow - literal controls - nice....

lblNavigation.Controls.Add(New LiteralControl(" \ Weddings"))

worked a treat :eek:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top