How to set width and height of image using HyperLink Control?

G

Guest

Dear friends,

I'm dynamically creating a Hyperlink with spacer.gif as ImageURL that is an
1px transparent image only to determine link position, but as I create this
link dynamically I could not set image width. This problem makes my link
clickable only on its borders.

When viewing HTML source I could see that spacer.gif has no width and
height, so HTML shows only 1px x 1 px image.

What can I do to make all the area clickable?

CODEBEHIND
-----------------
Dim myHyperLink as HyperLink
myHyperLink = New HyperLink
myHyperLink.ID = "link1"
myHyperLink.ImageUrl = "spacer.gif"
myHyperLink.NavigateUrl = "default.aspx"
myHyperLink.Attributes("style") =
"style="border-width:1px;border-style:Dotted;height:40px;width:128px;Z-INDEX:
103; LEFT: 408px; POSITION: absolute; TOP: 208px"
PlaceHolder1.Controls.Add(myHyperLink)

HTML SOURCE GENERATED BY DYNAMIC LINK
 
J

Juno

Hi Robson ,

Try this:
Dim myHyperLink As HyperLink
myHyperLink = New HyperLink
myHyperLink.ID = "link1"
myHyperLink.NavigateUrl = "default.aspx"
myHyperLink.Attributes("style") =
"style=border-width:1px;border-style:Dotted;height:40px;width:128px;Z-INDEX:
103; LEFT: 408px; POSITION: absolute; TOP: 208px"
Dim img As New WebControls.Image
img.ImageUrl = "spacer.gif"
img.Width = Unit.Pixel(100)
img.Height = Unit.Pixel(100)
myHyperLink.Controls.Add(img)
PlaceHolder1.Controls.Add(myHyperLink)
 
G

Guest

Dear Juno,

Thanks for your help!

The solution has worked in part.

As you can see, my links are placed by a Function named AddControls.

By using your solution only the last HyperLink placed receives img.width and
img.height.

Can you help me with the correction of the below code?


Public Class dynamic
Inherits System.Web.UI.Page
Dim myHyperLink As HyperLink
Dim img As New WebControls.Image

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
AddControls(“link1â€,
“border-width:1px;border-style:Dotted;height:40px;width:128px;Z-INDEX: 103;
LEFT: 408px; POSITION: absolute; TOP: 208pxâ€, “default.aspxâ€)
AddControls(“link2â€,
“border-width:1px;border-style:Dotted;height:40px;width:128px;Z-INDEX: 103;
LEFT: 488px; POSITION: absolute; TOP: 208pxâ€, “services.aspxâ€)

End Sub

Sub AddControls(ByVal ObjectName As String, ByVal Style As String, ByVal
NavigateUrl As String)
myHyperLink = New HyperLink
myHyperLink.ID = ObjectName
img.ImageUrl = "/corretoresdeseguros/images/spacer.gif"
img.Width = Unit.Pixel(100)
img.Height = Unit.Pixel(100)
myHyperLink.Controls.Add(img)
myHyperLink.NavigateUrl = NavigateUrl
myHyperLink.Attributes("style") = Style
PlaceHolder1.Controls.Add(myHyperLink)
End Sub

End Class
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top