Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

ASP.NET: Hooking up an image stored in mssql, with Lightbox

Options
  • 21-07-2010 8:29am
    #1
    Closed Accounts Posts: 585 ✭✭✭


    Hi folks,

    I've an image stored in my mssql DB, I'd like to display it on a webpage using Lightbox which darkens out the main page (background) and presents the image in a nice white frame.

    I can get my solution to work when I store the image in a folder and reference it in my DB, (I'm using a repeater so each image HREF needs to be different depending on what record is returned from the DB), however ideally I'd like to use the stored image in my DB and return a link to the image in the DB with the other data from the DB that gets returned and if the link is clicked, then the image gets displayed via Lightbox.

    There is no shortage of fixes on the internet for how to do this where the image is stored in a folder and the HREF is stored in the DB however this isn't really the fix I'm looking for and when I go through the fixes available on the web for retreiving an image from a DB, it involves using write.response and opening a new aspx page which also isn't what I want to do...

    <td valign="top" align="right"><b>Image: </b></td><td>
    <script type="text/javascript" src="js/prototype.js"></script>
    <script type="text/javascript" src="js/scriptaculous.js?load=effects"></script>
    <script type="text/javascript" src="js/lightbox.js"></script>
    <link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
    <a href="Images/madnight.jpg" rel="lightbox">View Folder Image</a>
    <a id="LightBox_Content" href="<%# ((Product)Container.DataItem).ImageData %>" rel="Lightbox">View DB Image</a>


    In the code snippet above, I can get the solution to work perfectly for the "View Folder Image", but not for the "View DB Image"...???

    Thanks in advance for any help with this...

    Mr.D


Comments

  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    MrDarcy wrote: »
    when I go through the fixes available on the web for retreiving an image from a DB, it involves using write.response and opening a new aspx page which also isn't what I want to do...
    In a way this actually is what you want to do. The lightbox needs a URL for the image it's going to display (unless you find another lightbox control or write your own that will take the image directly from a DB).

    What you will need to do is set up a page that returns your image from the DB, for e.g. http://mysite/getImage.aspx?ImageID=123, then provide that URL to the lightbox to display it.


  • Closed Accounts Posts: 585 ✭✭✭MrDarcy


    stevenmu wrote: »
    In a way this actually is what you want to do. The lightbox needs a URL for the image it's going to display (unless you find another lightbox control or write your own that will take the image directly from a DB).

    What you will need to do is set up a page that returns your image from the DB, for e.g. http://mysite/getImage.aspx?ImageID=123, then provide that URL to the lightbox to display it.

    Thanks Steve, I had thought about that approach but I thought the outcome would be that I'd end up with a Lightbox "window" with my image AND also a new pop up window called getImage.aspx with my image also in it, effectively giving me two windows where I want only one???


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    MrDarcy wrote: »
    Thanks Steve, I had thought about that approach but I thought the outcome would be that I'd end up with a Lightbox "window" with my image AND also a new pop up window called getImage.aspx with my image also in it, effectively giving me two windows where I want only one???
    No, I think stevenmu's should work. If you set the http header content type to image/png or what ever. Then there is no difference than it fetching a static image at that URL.


  • Closed Accounts Posts: 585 ✭✭✭MrDarcy


    Webmonkey wrote: »
    No, I think stevenmu's should work. If you set the http header content type to image/png or what ever. Then there is no difference than it fetching a static image at that URL.

    Ok thanks for that WebMonkey I'll give this a shot...


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    Webmonkey wrote: »
    No, I think stevenmu's should work. If you set the http header content type to image/png or what ever. Then there is no difference than it fetching a static image at that URL.

    Exactly, the aspx page doesn't return a 'page' it actually just returns the raw image with the correct content type set, as far as the browser is concerned it's just a regular image file being downloaded


  • Advertisement
  • Closed Accounts Posts: 585 ✭✭✭MrDarcy


    Thanks so much lads for the help with this, here goes...!


  • Closed Accounts Posts: 585 ✭✭✭MrDarcy


    Just got the perfect result lads, thanks so much to the two of you for putting me right, I've been at this for the last week!


  • Closed Accounts Posts: 585 ✭✭✭MrDarcy


    For all my optimism, I've uploaded this to my webserver and what has been working perfectly on my dev environment on my laptop now doesn't work from the remote web url, the Lightbox opens up all right and shades out the webpage in the background but it can't load the image even though the Id and URL is correct and all that when I hover over the link button???

    I've checked that I've all the Lightbox files properly referenced but no joy, any ideas?!? Hard to see why it works when running from one place and not another??? When I just use an ordinary image in a folder to test the Lightbox on the remote site it works fine, which makes me think its an issue with reading the image data... :confused::confused::confused:


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    When happens when you go to the getimage.aspx file directly , do you see an image download?


  • Closed Accounts Posts: 585 ✭✭✭MrDarcy


    Webmonkey wrote: »
    When happens when you go to the getimage.aspx file directly , do you see an image download?

    You can't buy experience Webmonkey! Your suggestion above made me cop the issue, I forgot to upload updated dll files to the remote server and when I tried your idea I got an error saying the namespace type couldn't load so I updated the dll files and that sorted it out, thanks again for your help!

    Everything is hanging together as it should now, thanks again guys, this house has been blessed!


  • Advertisement
  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    MrDarcy wrote: »
    You can't buy experience Webmonkey! Your suggestion above made me cop the issue, I forgot to upload updated dll files to the remote server and when I tried your idea I got an error saying the namespace type couldn't load so I updated the dll files and that sorted it out, thanks again for your help!

    Everything is hanging together as it should now, thanks again guys, this house has been blessed!
    ha ha no problem. Best of luck :)


  • Closed Accounts Posts: 585 ✭✭✭MrDarcy


    Hi Folks...

    I'm fiddling around with this solution tonight trying to get a different page to display a GridView for me, thinking as per above that I can use a href like:

    <td valign="top" align="right"><b>Image: </b></td><td>
    <script type="text/javascript" src="js/prototype.js"></script>
    <script type="text/javascript" src="js/scriptaculous.js?load=effects"></script>
    <script type="text/javascript" src="js/lightbox.js"></script>
    <link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />

    <a href="ViewInfo.aspx" rel="lightbox">View Info</a>

    The GridView displays fine when I run my ViewInfo.aspx page on its own, (I've hardcoded in an Id record value for the table so it returns a particular row which it does no probs).

    But when I try to run it via the link below in another page:

    <a href="ViewInfo.aspx" rel="lightbox">View Info</a>

    The lightbox just hangs...

    Just wondering am I wasting my time fiddling with this, like is there some reason why GridView, etc, cannot be viewed using Lightbox??? I was just thinking that because of the way the Lightbox can load an image stored in a DB via a reference to another aspx page, without actually opening the page itself, that maybe the same might hold true for stuff like GridView, DetailsView, etc???

    Just curious about this, thanks for any help with it!


  • Closed Accounts Posts: 585 ✭✭✭MrDarcy


    Still stuck with this if anyone can advise me if a GridView on a page can be displayed via Lightbox just like an image?


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    MrDarcy wrote: »
    Still stuck with this if anyone can advise me if a GridView on a page can be displayed via Lightbox just like an image?
    I'm not too familiar with grid view in ASP.NET but I believe the output is just regular HTML. I don't think that would work. Lightbox can only display image files.

    Actually it does seem mods have been made to display a page inside of a lightbox pop up. If you do some goggling you can see some discussions on the topic.


Advertisement