Link to home
Start Free TrialLog in
Avatar of scm0sml
scm0sml

asked on

adding an image to an image button using css

I have the following css class:
.POWMoreInfo
{
   background: url("../images/btn_info_org.png") top left no-repeat;
}

I then have the image button:
<asp:ImageButton ID="btnMoreInfo" runat="server" PostBackUrl="../Advertising.aspx" AlternateText="More Information" />            

in my code behind i set the css class of the button to use the class i have shown here.

This works but i also get an error image because i have not set imageurl for the button.

Is there a way around this?

I have attached a screenshot just to show what i mean.
example.jpg
Avatar of Saqib Khan
Saqib Khan
Flag of United States of America image

Try..

.POWMoreInfo
{
   background: url("<%=ResolveUrl("~")%>images/btn_info_org.png") top left no-repeat;
}
Avatar of scm0sml
scm0sml

ASKER

its not a problem with the css. the image is showing from the css.

its the image button thats moaning
I dont see a "src/source" attribute for your image button.
Avatar of scm0sml

ASKER

the question says it happens in the code behind.

this is the code to do it:
btnMoreInfo.CssClass = "POWMoreInfo"
Don't think you can do it with ImageButton. Try LinkButton instead.
If you do decide to use LinkButton, make sure you add display:block in your CSS.
Avatar of scm0sml

ASKER

couldnt get it working.

cant believe how much time ive spent trying to do something so simple :(
You mean LInkButton does not work for you?
Avatar of scm0sml

ASKER

nope
ASKER CERTIFIED SOLUTION
Avatar of prairiedog
prairiedog
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of scm0sml

ASKER

yeah ok that is now showing the image.

while u r on a roll can u see what is wrong with this?

.POWMoreInfo
{  
 background:url("../images/btn_info_org.png") top left no-repeat;
      display:block;
      width:98px;
      height:25px;

}

.POWMoreInfo a:hover
{  
    background:url("../images/btn_info_org2.png") top left no-repeat;
      display:block;
      width:98px;
      height:25px;
}

i have just changed the image name wanting it to show a different image when u hover over the button
Change .POWMoreInfo a:hover
To:
 .POWMoreInfo:hover
Avatar of scm0sml

ASKER

top man!