Click here to Skip to main content
11,930,788 members (56,636 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET GDI
Hello there,

Being new to ASP.Net but ok with winForm I rather naively thought I could create an image button on the fly and put an image on it (rather than an ImageURL).

The problem is this -

I want to create an imagebutton in my gridview. I am placing this in at design time and each row needs a custom image based on some values in the row. No problem with creating the image (using GDi+) but assigning it to the button seems impossible.
Dim B As New ImageButton
B.CommandArgument = "RowNum"
B.CommandName = "AddMerit"
If ImageButton had an 'image' property then this would be trivial. However, it only has an ImageURL. I suppose that I could create the image, save it on the server and then reference it, but this would be difficult and messy to clean up. I have tried to understand how I might use a webmethod to serve the image, but this also seems expensive for a table of 30-40 rows - I would prefer to set the images before they are sent to the server....

Any help would be appreciated.
Posted 3-Jul-12 3:09am
Edited 3-Jul-12 20:03pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I have found a solution but I cannot believe it is optimal! The solution is to build a complete page with the following code in the page load:
Dim FinalBitmap As Bitmap
Dim NumMerits = Request.Params("Merits").ToString
Dim BarGraphPercent = Request.Params("BarGraph").ToString
Dim msStream As New MemoryStream
 'Code here to populate FinalBitmap with the image

FinalBitmap.Save(msStream, ImageFormat.Png)
Response.ContentType = "image/png"
If Not IsNothing(FinalBitmap) Then FinalBitmap.Dispose()

In the main page I then link each row to a "~/Pages/Register/GetGraph?Merits=3&BarGraph=80" (or whatever that student's figures are)

This then results in 30 calls to the server, one for each image. Surely there is a better way than this!
enhzflep 3-Jul-12 10:08am
edit Gday /edit

Sounds like you may benefit from using the Data URI scheme. More here:
Tim_1024 3-Jul-12 11:26am
Thanks for this - it does look promising. Do you have any examples?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I have not really found an acceptable solution - the sub optimal solution works, but the page takes ages to load each image. In the end I created images for each criteria - 400 images - and referenced these.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 13 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100