Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a link that contains an image & text?

I need to create a link for an ASP.NET page that has an image & text, which when clicked will trigger an event on the webserver.

This is what the link should look like: enter image description here

This is the HTML for what the link would look like if I wasn't working with ASP.NET:

<a id='PdfLink' href='#'>
    <img src="App_Themes/.../Images/PDF.gif" alt="Click for fact sheet PDF"/>
    <span>Latest Performance</span>
</a>

The problem with this is that I want to be able to click this and trigger an server-side event, but I don't know if I can do that with plain old HTML controls.

With ASP.NET I can see that there are various controls such as ImageButton & HyperLink but I don't see how I can have a Hyperlink & an ImageButton as part of the same clickable control.

What's the best way for me to get a link similar to the image that is bound to server-side functionality?

like image 401
DaveDev Avatar asked Aug 26 '11 10:08

DaveDev


People also ask

How do I make a clickable link in a JPEG?

Right-click the image and select "Link" from the drop-down menu. Type or paste the hyperlink address into the "Address" field.

How do I make an image part of a clickable?

To create clickable areas in an image, create an image map, with clickable areas. For example, on clicking a box, the different website opens and on clicking a triangle in the same image, a different website opens.


2 Answers

I wouldn't do this by using a mixture of controls.

I would use a <asp:LinkButton> control

<asp:LinkButton id="LinkButton1" runat="server" OnClick="ButtonClick_Event" CssClass="latest-performance">Latest Performance</asp:LinkButton>

Then I would use the CssClass "latest-performance" to style up the link.

e.g.

.latest-performance{
     display: block;
     padding-left: 20px;
     background: url(url-to-the-pdf-icon) no-repeat left center;
}

You will have to tweek the style to fit with what you need, but this will basically look exactly the same as what you need. It also keeps your code clean, and separates out the style.

like image 160
Tim B James Avatar answered Nov 15 '22 02:11

Tim B James


You can do like..

<asp:LinkButton ID="LinkButton1" runat="server" 
Text="<img src='App_Themes/.../Images/PDF.gif' /> PdfLink"></asp:LinkButton>
like image 27
Muhammad Akhtar Avatar answered Nov 15 '22 04:11

Muhammad Akhtar