Search code examples
vb.netfacebookhyperlinkdatalist

Need a Hyperlink control to do several things at once


On my site I have a DataList full of image thumbnails. The thumbnails are HyperLink controls that, when clicked, offer an enlarged view of the source image (stored in my database).

My client wants a facebook Like button on each image and I was hoping to put that in the lightbox window that appears when you click on a thumbnail. My challenge here is that to generate the info for the Like, I need to create meta tags and each image should, preferably, create it's own meta tags on the fly.

What I can't figure out is how to make the HyperLink click open the lightbox AND create the meta tags at the same time.

Any help will be greatly appreciated.

For a live view of the site, go to http://www.dossier.co.za


Solution

  • The way that we approach similar problems is to hook the onclick event of the href in javascript.

    Depending on exactly what you need to do, you can even prevent the standard browser behavior for the hyperlink from executing by returning false from the javascript method.

    And in some cases, we just use the hyperlink for "show" by setting the href to "#".

    Here is an example that combines all of these concepts:

    <a href="#" id="lnkFile" runat="server" onclick="javascript:{cmdFile_Click(); return false}" title="View the file">File Name</a>
    

    In this case, the specified javascript is executed, there is no real hyperlink, and the browser doesn't try to navigate to the specified URL because we return false in the javascript.