Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have one asp.net image control in which i bind image from code behind. I want when i click on this image control it shows this image as pop up.
ASP.NET
<asp:Image ID="Image1" Height="100" Width="100" style="cursor: pointer" runat="server" />

C#
Image1.ImageUrl = "~/Image/" + Convert.ToString(reader["imagepath1"]);
Posted

Hi Raj,

If we bind the imageurl on click of the image it unnecessarily goes for a postback, so it is better to bind the url at the first go only and keep in hidden mode.

Actually no need of having the asp:Image control simple img tag can also solve this problem.

The below code will show an image in popup on click of the button. Please change this ti suit your requirement.

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="jquery-ui-1.8.24.min.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            $("#MyImage").dialog({
                autoOpen: false
            });
            $('#ClickMe').on('click', function () {
                $('#MyImage').dialog("open");
            });
        });
    </script>
</head>
<body>
    
        <button id="ClickMe">Click to view Image</button>
         <asp:image id="MyImage" runat="server" style="display: none" imageurl="~/276609a.jpg" xmlns:asp="#unknown" />
    
</body>
</html>

Thanks
Srikant
 
Share this answer
 
I used ThickBox It is quite good and easy to implement.
Just add js and css file to page.
XML
<script src="Script/ThickBox.js" type="text/javascript"></script>
<link href="Css/ThickBox.css" rel="stylesheet" type="text/css" />

Small image inside image tag and full image inside <a> tag.
Remember to define <a> class name as "thickbox" only.
ASP.NET
<a class="thickbox" id="Image6" runat="server"><asp:image id="Image1" height="100" width="100" style="cursor: pointer" runat="server" xmlns:asp="#unknown" /></a>

C#
Image1.ImageUrl = "~/Image/" + Convert.ToString(reader["imagepath1"]);
Image6.HRef = "~/Image/" + Convert.ToString(reader["imagepath1"]);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900