Solved

adding an image to an image button using css

Posted on 2008-10-02
12
366 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:scm0sml
  • 6
  • 4
  • 2
12 Comments
 
LVL 23

Expert Comment

by:adilkhan
ID: 22627042
Try..

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

Author Comment

by:scm0sml
ID: 22627058
its not a problem with the css. the image is showing from the css.

its the image button thats moaning
0
 
LVL 23

Expert Comment

by:adilkhan
ID: 22627068
I dont see a "src/source" attribute for your image button.
0
 

Author Comment

by:scm0sml
ID: 22627370
the question says it happens in the code behind.

this is the code to do it:
btnMoreInfo.CssClass = "POWMoreInfo"
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22627872
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.
0
 

Author Comment

by:scm0sml
ID: 22628082
couldnt get it working.

cant believe how much time ive spent trying to do something so simple :(
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:prairiedog
ID: 22628121
You mean LInkButton does not work for you?
0
 

Author Comment

by:scm0sml
ID: 22628131
nope
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 500 total points
ID: 22628169
How about adding width and height in your CSS?
width:32px;
height:32px;
Change the numbers to match your actual image size. Remember, you will also need to add display:block; in your css.

.POWMoreInfo

{

	background:url("("../images/btn_info_org.png") top left no-repeat;

	display:block; 

	width:32px;

	height:32px;

}

Open in new window

0
 

Author Comment

by:scm0sml
ID: 22628241
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
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22628411
Change .POWMoreInfo a:hover
To:
 .POWMoreInfo:hover
0
 

Author Closing Comment

by:scm0sml
ID: 31502488
top man!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now