I am loading an asp image into my site and its showing in the design view but when I run it on the local host it wont display the image.
<div><asp:Image ID="Image1" runat="server" src="~/images/FusionChart.png" /></div>
the image is stored in "images" folder within the root and the image name is the exact same as in the div so Im confused as to why is wont display. Any help would be appreciated.
Seems like your path is incorrect. Please read this article, may be help you
http://msdn.microsoft.com/en-us/library/ms178116.aspx
If not there is different
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/FusionChart.png"/>
<img src="~/images/FusionChart.png" alt=""/>
Change the src attribute name to ImageUrl property name
Related
I want to show an image on my website from a folder which is outside the asp.net application on my desktop. I have tried this but it is not uploading the image.
<asp:Image ID="Image2" runat="server" ImageUrl="C:\Users\MyName\Desktop\Images\0.jpg" />
Is there any other way to give the path. What is wrong I am doing. Please advise. Thanks in advance.
I have a image control on a asp.net page and the imageurl is set. The image shows normal in the designer but doesnt open in the browser?? What can be wrong with it? What else should be set then the image url???
Help much appreciated
<form id="form1" runat="server">
<div class="style1">
<h1>A Basic Website<asp:Image ID="Image2" runat="server" Height="93px"
ImageAlign="Right" ImageUrl="~/App_LocalResources/Winter.jpg" Width="263px" />
</h1>
<img src="~/Images/mypic.jpg" alt="My Pic" runat="server" />
Use the tilda (~/) operator and the runat attribute so that the path resolves on the server side.
I also suggest not using designer view - use code view and your browser for regular design work. Try the Firefox Web Dev Toolbar.
To use the image control:
<asp:Image ID="Image1" runat="server"
ImageUrl="~/Images/ASPdotNET_logo.jpg"
AlternateText="ASP.NET Logo">
Here's a walkthrough...
Thank you sooooooo much for the help, I found the solution, I was using app_resources folder which didnt work, but when I renamed the folder it did.... so thanks for taking the time to show the way :)
ill try my best to explain this..
in the site.master I have added a logo to the title like so.
<div class="title">
<img alt="" class="style1" src="Images/logo.png" />
</div>
the logo shows up fine in all pages accept when the url is part of the account.
for example..
"http://localhost:54341/Sitename/mypage.aspx" (shows fine)
however
"http://localhost:54341/Sitename/Account/Register.aspx" (doesnt show)
im guessing its because it is in a parent folder (the images file).
Is there a better way?
EDIT: Images folder is at the top level
thanks in advance
Try using relative path with respect to root of the application:
<img alt="" class="style1" runat="server" src="~/Images/logo.png" />
Explaination:
ASP.NET includes the Web application root operator (~), which you can use when specifying a path in server controls. ASP.NET resolves the ~ operator to the root of the current application. You can use the ~ operator in conjunction with folders to specify a path that is based on the current root.
The following example shows the ~ operator used to specify a root-relative path for an image when using the Image server control In this example, the image file is read from the Images folder that is located directly under the root of the Web application, regardless of where in the Web site the page is located.
<asp:image runat="server" id="Image1"
ImageUrl="~/Images/SampleImage.jpg" />
You can use the ~ operator in any path-related property in server controls. The ~ operator is recognized only for server controls and in server code. You cannot use the ~ operator for client elements.
This should do it...
<img alt="" class="style1" src="<%=ResolveClientUrl("~/Images/logo.png")%>" />
#Kevin Main suggested : You need to put runat="server" on the image for this to work.. this worked a treat
This will work for localhost:54341/Sitename/Account/Register.aspx
<img alt="" class="style1" src="../Images/logo.png" />
Hi all my work environment is asp.net c# vs2008. My issue is this, i have a master page outside.master in shared folder.Inside it i have an image control with
<img src="App_Themes/Home/images/logo.png" />
i am referring this master page from in two sub pages. One is Index.aspx which is located in the root level and Secondly registration.aspx which is under masters folder. The problem is that when i run, the index.aspx will show the logo where registration.aspx is not showing the logo. Please tell me how to specify the path so that i will get logo in both pages.
Tilde sign ~ will resolve for server side controls.
So you need to add runat="server" as img in HTML element.
Try this:
<img src="~/App_Themes/Home/images/logo.png" runat="server"/>
The most foolproof method is to have something like this
<asp:Image runat="server" id="myImage" ImageUrl='<%# Eval("imageFile") %>' />
Then in the code-behind assign the variable imageFile to something like Server.MapPath("App_Themes/Home/images/logo.png");
Try the following:
<img src="~/App_Themes/Home/images/logo.png" runat="server" />
What is the correct way to reference an image in ASP.NET for live deployment on IIS?
The following works in dev and production:
<asp:ImageButton ID="ibnEdit" runat="server" OnClick="ibnEdit_Click" ImageUrl="~/App_Themes/Default/images/one.png" Visible="false" ToolTip="Edit" />
The following doesn't work in either: (why not?)
<img src="~/App_Themes/Default/images/two.gif" />
The following works in dev but not in production:
<img src="../App_Themes/Default/images/two.gif" />
If you want to use a regular img tag with the ~ path, you can just add runat="server" into the tag as an attribute (like regular server controls) and the path will be resolved. e.g:
<img src="~/App_Themes/Default/images/two.gif" runat="server" />
For your second part, is the ../ image reference appearing on more than one page, for example a user control or master page (etc) such that you might be using it at different folder levels...
I use this syntax for access images from master pages
<img src="<%=ResolveUrl("~/Content/Images/error_img.jp")%>" width="350" style="padding-right: 15px; padding-top: 20px;"/>
The ~ will only work on a server control such as <asp:Image> or <asp:ImageButton>. This tells ASP.Net to insert the application path. Sometime that's just "/" but if your application is not the root directory of the website it will include the path it is in. The img tag is just html and it will not be altered by ASP.Net, so the browser gets the path "~/App_Themes/Default/images/two.gif" and doesn't know how to read it.
I don't know why the last example works in dev but not in production. It might has something to do with having the application in the root directory in dev but in a sub directory in production.
This worked for me
$(".selector").attr('src', "Content/themes/base/images/img.png");
The important is that you do not have "/" at the beginning of your new src.
byte[] imageArray = System.IO.File.ReadAllBytes(Server.MapPath("~/Images/Upload_Image.png"));
string base64ImageRepresentation = Convert.ToBase64String(imageArray);
You can look into my answer . I have resolved the issue using C# language.
Why can't I do <img src="C:/localfile.jpg">?