Search code examples
jqueryasp.netimagesrc

Image src using Jquery


I have the image path as shown below:

<img src='Uploads/" + document.getElementById("<%=currentDirectory.ClientId%>").value + "/" + file.name + "' width='70' height='55'/>

And Now I want to click this thumbnail image in order to display its orginal image. For that I am doing like this:

 $(".imgContain").click(function () {
                $('#<%=largeImage.ClientId%>').attr('src','Uploads/" + document.getElementById("<%=currentDirectory.ClientId%>").value + "/" + file.name + "');

  });

When I do this way and checked its src it's showing me as "Failed to load give URL". Can anyone edit me this src or point me out which is the best way to do this?

This is my HTML part:

<div id="thumbs" class="imgContain" runat="server">
    </div>

<asp:Image ID="largeImage" runat="server" 
        style="position:relative;width:450px;height:345px; margin-left:430px;margin-top:-415px; margin-bottom:30px;" 
        BorderColor="#666666" BorderStyle="Dashed" BorderWidth="4px"/>

Solution

  • yeah that string a little off. Try it like this:

    $('.imgContain').click(function () {
        $('#<%=largeImage.ClientId%>').attr('src','Uploads/' + $get('<%=currentDirectory.ClientId%>').value + '/' + file.name);
    });
    

    it was kind of confusing because single and double quotations were being used interchangeably.