468,117 Members | 1,980 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,117 developers. It's quick & easy.

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

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
--------------------------------------------------------
<a id="a_empresa" href="aempresa.aspx"
style="position:absolute;left:415px;top:130px;widt h:73px;height:20px;"><img
src="/corretoresdeseguros/images/spacer.gif" border="0" /></a>

Nov 18 '05 #1
2 6198
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)

--
Juno
MCSD.NET, MCDBA, MCSE
----------------------------------------------------------
Support Team of EasyDotNet, INC. http://www.EasyDotNet.com
DataForm.NET - The most powerful data entry web server control for ASP.NET

"Robson Carvalho Machado" <Ro*******************@discussions.microsoft.com >
wrote in message news:A8**********************************@microsof t.com...
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
--------------------------------------------------------
<a id="a_empresa" href="aempresa.aspx"
style="position:absolute;left:415px;top:130px;widt h:73px;height:20px;"><img src="/corretoresdeseguros/images/spacer.gif" border="0" /></a>

Nov 18 '05 #2
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

"Juno" wrote:
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)

--
Juno
MCSD.NET, MCDBA, MCSE
----------------------------------------------------------
Support Team of EasyDotNet, INC. http://www.EasyDotNet.com
DataForm.NET - The most powerful data entry web server control for ASP.NET

"Robson Carvalho Machado" <Ro*******************@discussions.microsoft.com >
wrote in message news:A8**********************************@microsof t.com...
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
--------------------------------------------------------
<a id="a_empresa" href="aempresa.aspx"

style="position:absolute;left:415px;top:130px;widt h:73px;height:20px;"><img
src="/corretoresdeseguros/images/spacer.gif" border="0" /></a>


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Christian Pick | last post: by
1 post views Thread by Mustafa Rabie | last post: by
1 post views Thread by Nathan Sokalski | last post: by
8 posts views Thread by Nathan Sokalski | last post: by
1 post views Thread by Daves | last post: by
8 posts views Thread by Kentor | last post: by
2 posts views Thread by Atul | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.