Click here to Skip to main content
12,890,211 members (44,616 online)
Click here to Skip to main content
Add your own
alternative version


3 bookmarked
Posted 27 Feb 2011

Showing Transparent Image in Browsers

, 28 Feb 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Showing Transparent Image in Browsers


Showing .png images in browsers. It is very simple to show images in broswers, but PNG images in IE browsers display with background and other browsers like Firefox showing PNG images with transparancy, because they are supporting.

Browser Outputs

To view broswer output, click here.


To download solution,
click here.

HTML Block

Past below code in form tag of ASP.NET default.aspx page.
<table border="1">
<tr><td><b>Image With Background</b></td><td><b>Image Without Background</b></td></tr>
<td align="center"><asp:Literal ID="ltlOne" runat="server"/></td>
<td align="center"><asp:Literal ID="ltlTwo" runat="server"/></td>

Code Part

Past below code in default.aspx.cs page.ShowTransParentImage() function uses div tag with style to show PNG image in Internet Explorer. Check browsers with this code Request.Browser.Browser. If browser is not Internet Explorer, then use simple img tag to show PNG image.

    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
    protected void ShowTransParentImage()
        string sImg = string.Empty;
            string sT1 = "printer.png";
            string sTemp = "<DIV ID=\"oDiv1" + "\" STYLE=\" height:16px; width:16px; filter: progid: DXImageTransform.Microsoft.AlphaImageLoader(src='" + sT1 + "', sizingMethod='scale'); border:0px;\" />";
            sImg = "<img src=\"" + sT1 + "\" border=\"0\"/>";
            ltlOne.Text = sImg;
            if (Request.Browser.Browser == "IE")
            { sImg = sTemp; }
            ltlTwo.Text = sImg;
        catch (Exception ex)
        { }        


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


About the Author

R S Dodiya
Software Developer (Senior)
India India

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 28 Feb 2011
Article Copyright 2011 by R S Dodiya
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid