I need to use the asp control "ImageButton" in order to have access to the properties "OnClick" and "OnClientClick"
The problem is i cannot give any ImageURL since my Image is in Database.
I used this previously :
<telerik:RadBinaryImage runat="server" ID="RadBinaryImage1" DataValue='<%#Eval("Image") %>'
AutoAdjustImageControlSize="false" Width="90px" Height="110px" Enabled="true" AlternateText="pas d'image"/>
But i don't have any Datavalue property in ImageButton control...
How can i manage to do this using ImageButton?
thanks in advance
You can use a Generic Handler file and call that as your ImageUrl like:
<asp:ImageButton ImageUrl='<%# String.Format("Image.ashx?id={0}", eval("ID")) %>' />
Read more on how to do this here:
http://www.dotnetcurry.com/ShowArticle.aspx?ID=129
The fact its an ImageButton makes no difference. It's the fact you want to render an image from image data type. I believe generating the image on the fly using a Generic Handler file is the most common way.
You can use handler for creating image from database or from binary format and this handler you can call from your imagebutton -> imageURL and it will show the image on the page.
You may provide a method that will return an image as stream. Your URL may be:
http://www.yourwebsite.com/Application/Images/GetImage?name=myImageName&format=png
Inside your site you'll provide a GetImage page to query the database and write in the output stream the image data (do not forget to set the mime type).
Related
I want to create a website which will store 2 images in the "home" page, which will lead to 2 different pages. In the case, I'm using the Image object from the toolbox. When I'm trying to assign the ImageUrl, it don't appear to find anything at all, regardless of the format. I've tried with multiple photos, different folders, there's the result:
I've also tried to change it programatically in C#, not working, as well:
Image1.ImageUrl = #"Images/left.jpg";
Should I use the usual <img src=""/> for finding images? Thank you very much!
Right click on that image shown and choose "include in project" and then try to give imageUrl
If you are sure that your path value contains the appropriate path from the ImageFiles directory, then you should be able to use the following :
<asp:Image ID="Image1" runat="server" ImageUrl='~/ImageFiles/<%# Eval("path")%>' />
or use the integrated string formatting of the Eval method as shown here :
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("path", "~/ImageFiles/{0}") %>' />
From the code behind you could do something like below including application base URL some thing like below-
Image1.ImageUrl = #"~/Images/left.jpg"
Please refer the below discussion for more information -
Image isn't showing in Image and ImageButton
ASP.NET will automatically replace the ~ with your application's base
URL, because Image1 is a server control
so started using a new method for dynamicly displaying images inserted into my database. This is the asp.net code
<asp:ImageButton ID="ImageButton1" ImageUrl='<%#Eval ("ImageUrl", "~/img/{0}") %>' Width="200px" PostBackUrl='<%#Eval ("ProductID", "Product.aspx?ProductID={0}") %>' runat="server" />
now, as you can see what it does is getting the "ImageUrl" from my database depending on what the ProductID is, and then shows that as the image url. Example in my folder /img/ i have a picture called "pic.jpg" then this code would make the image url "~/img/Pic.jpg" now how would i add a new image into the table from the backend? i would have to make a flileupload control upload the file to the "img" folder and then insert only the file name as the "ImageUrl" in the database table. How is this done? do you have any examples or can point me in the right direction?
thanks!
all answers appreciated!
ImageButton is actually a html input type image. So you should not use it for just display purposes. You can use Image control or even use html img tag.
Check this link for FileUpload control
http://asp.net-tutorials.com/controls/file-upload-control/
Check this link for Image control
http://www.w3schools.com/aspnet/showaspx.asp?filename=demo_image
How to display an Image if I have the Physical Path of that image in webpage in a particular place?
I tried like below but not working.
img = rdr["ImagePath"].ToString();
img = Server.MapPath(img);
Image1.ImageUrl=img;
I believe it would be as below:
ImageInstanceName.ImageUrl = Server.MapPath(#"/Images/image.jpg");
Or if you were wanting to do it in markup then #Bibhu's solution should work.
Here is the link to MSDN library on Server.MapPath.
You can create an Handler which returns the binary output of that image. and in your image tag refer to this handler
eg. <img src="yourImagehandler.ashx"/>
In C# -
Image1.ImageUrl = Server.MapPath("c:\path\to\file.jpg");
<asp:Image id="Image1" runat="server"
AlternateText="Image text"
ImageAlign="left"
ImageUrl="images/image1.jpg"/>
In .NET(C#), I'm loading an image. The src of the image is stored in the database.
I currently retrieve text from my db using this:
TextBox4.Text = reader["descr"].ToString(); // snippet
However, I want to know, how would I display an image?
Image1.Text= reader["img1"].ToString();
and then in my WebForm:
<asp:Image ID="Image1" runat="server" />
Use the ImageUrl property instead.
Try
Image1.ImageUrl = reader["img1"].ToString();
Have you tried Image1.ImageUrl = reader["img1"].ToString();
This one has been answered many times on so:
Basically you need to create an image handler to load the binary stream of the image to the browser. Also if you are going this route, please remember to use the cache header for each image so you are not pulling data from your database on every request.
ASP.NET [Image Handler]
Enjoy!
How to add System.Drawing.Image object to Asp:Image Control but I dint have imageId in my table.Image field is in another table..i retrieve image from database in Image object.i want to display it in asp:Image control or grid view.how to do it?? pls send reply... C#
The Image class and <asp:image> control are completely different thing.
You need to have a page or http handler to write the Image object as an image file such as .jpg / .png / .gif. And then use the <asp:image> control to access the URL of your page or http handler to get the image file you generated and display it. <asp:image> basically only render a HTML <img> tag with the URL of the image.
You can use this ASP.NET module and the SqlReader plugin to serve images directly from the database.
You can then reference the images like so:
<asp:Image runat="server" ImageUrl="/sqlimages/[imageidhere]" />