Apply stylesheet to Hyperlink server control

R

Redhairs

When I set up a image link with Hyperlink server control as below
<asp:HyperLink ID="thelink" runat=server Text="thelink"
NavigateUrl="#toWhere" ImageUrl="theLinkIMage.gif" />
the html output will be <a href="#toWhere"><Img src="theLinkImage.gif"
style="border-width:0px;"></a>

How to remove the built-in style and apply style sheet to the <img> tag?
 
E

Eliyahu Goldin

Make your own style class in a stylesheet and assign it to the CssClass
property. Or make a rule for a or for img. You can make it apply to that
link only. There are many thinks you can make with css.
 
R

Redhairs

I have tried both way but they don't work.
If I set the CssClass of the HyperLink control, the class property will be
added to the <A> tag instead of the <Img> tag.
I also create css rule for img but the default style(border-width:0px" will
override the rule.

Eliyahu Goldin said:
Make your own style class in a stylesheet and assign it to the CssClass
property. Or make a rule for a or for img. You can make it apply to that
link only. There are many thinks you can make with css.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


Redhairs said:
When I set up a image link with Hyperlink server control as below
<asp:HyperLink ID="thelink" runat=server Text="thelink"
NavigateUrl="#toWhere" ImageUrl="theLinkIMage.gif" />
the html output will be <a href="#toWhere"><Img src="theLinkImage.gif"
style="border-width:0px;"></a>

How to remove the built-in style and apply style sheet to the <img> tag?
 
E

Eliyahu Goldin

Make your css class in this way:

border-width:2px!important;

And you don't have to use Hyperlink if it doesn't suit you. Just use html
markup with runat=server.


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


Redhairs said:
I have tried both way but they don't work.
If I set the CssClass of the HyperLink control, the class property will be
added to the <A> tag instead of the <Img> tag.
I also create css rule for img but the default style(border-width:0px"
will override the rule.

Eliyahu Goldin said:
Make your own style class in a stylesheet and assign it to the CssClass
property. Or make a rule for a or for img. You can make it apply to that
link only. There are many thinks you can make with css.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


Redhairs said:
When I set up a image link with Hyperlink server control as below
<asp:HyperLink ID="thelink" runat=server Text="thelink"
NavigateUrl="#toWhere" ImageUrl="theLinkIMage.gif" />
the html output will be <a href="#toWhere"><Img src="theLinkImage.gif"
style="border-width:0px;"></a>

How to remove the built-in style and apply style sheet to the <img> tag?
 
M

marss

When I set up a image link with Hyperlink server control as below
<asp:HyperLink ID="thelink" runat=server Text="thelink"
NavigateUrl="#toWhere" ImageUrl="theLinkIMage.gif" />
the html output will be <a href="#toWhere"><Img src="theLinkImage.gif"
style="border-width:0px;"></a>

Another variant is using nested IMG element instead of setting
ImageUrl property.
Something like this:
<asp:HyperLink ID="thelink" runat=server NavigateUrl="#toWhere"><img
src="theLinkIMage.gif"/></asp:HyperLink>

Regards,
Mykola
http://marss.co.ua
 
R

Redhairs

I need to use Image server control in order set the image programmatically
When I set up a image link with Hyperlink server control as below
<asp:HyperLink ID="thelink" runat=server Text="thelink"
NavigateUrl="#toWhere" ImageUrl="theLinkIMage.gif" />
the html output will be <a href="#toWhere"><Img src="theLinkImage.gif"
style="border-width:0px;"></a>

Another variant is using nested IMG element instead of setting
ImageUrl property.
Something like this:
<asp:HyperLink ID="thelink" runat=server NavigateUrl="#toWhere"><img
src="theLinkIMage.gif"/></asp:HyperLink>

Regards,
Mykola
http://marss.co.ua
 
M

marss

I need to use Image server control in order set the image programmatically

Just add runat="server" attribute and id.

<asp:HyperLink ID="thelink" runat=server NavigateUrl="#toWhere"><img
id="theLinkIMage" runat="server"/></asp:HyperLink>

Server-side code: theLinkIMage.Src = "theLinkIMage.gif"

Or use Image web control:
<asp:HyperLink ID="thelink" runat=server
NavigateUrl="#toWhere"><asp:Image id="theLinkIMage" runat=server
ImageUrl="theLinkIMage.gif"></asp:Image></asp:HyperLink>

Regards,
Mykola
http://marss.co.ua
 

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

Top