By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,797 Members | 1,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,797 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.