Image within a custom control

B

bobben

Does anyone know if it is possible to emit a imagebutton with a bitmap
within a custom control.
In other words; I want the custom control to be selfcontained, and not have
to rely on a aspx page to be able to display an imagebutton with a
dynamically stored image. (From a database or loaded from a resource file.)

All I can find is this:

(...)
MemoryStream tempStream = new MemoryStream();

bitmap.Save(Page.Response.OutputStream,ImageFormat.Gif );

But then I am relying on a separate aspx page as a source for my
imagebutton.

Anyone knows any good techniques?

Børge
 
J

Jiho Han

I doubt what you're trying to accomplish is possible if I'm getting you
correctly. I've been wanting to do something similar but I just don't see
how that can be achieved. Remember in order for an image to show up on a
HTML page is through <IMG> tag and that src must point at a resource, real
or not.

You can kind of make it self-contained and this is from a book.
Normally your control will be deployed using a setup program that installs
your control and related files in a predetermined location. For example,
you are guaranteed to have /aspnet_client folder under your webroot. i.e.
C:\inetpub\wwwroot\aspnet_client. It's guaranteed to be there because
ASP.NET uses it. Under it, there are folders and subfolders based on your
assembly name and version.

aspnet_client
system_web
1_1_4322

under it you will find a couple of .js files that ASP.NET uses for
validation and etc. You can have your setup file do the same and create a
folder underneath aspnet_client according to your assembly's name and
version and place all your client related files such as images, stylesheets,
..js scripts, behaviors, xml files, xsl files, and anything else you want.
And you can refer to the resources in your control.

Your machine.config file contains this section under system.web and so you
can retrieve the client file location without hardcoding it should they
change in the future or maybe you just want it in a different place
altogether.

<webControls clientScriptsLocation="/aspnet_client/{0}/{1}/"/>

You can retrieve the assembly information like this:

AssemblyName assemblyName = YourControl.GetType().Assembly.GetName();
string assembly = assemblyName.Name.Replace(".", "_").ToLower();
string version = assemblyName.Version.ToString().Replace(".", "_");

and just concat them.
This is straight out of Nikhil Kothari's server controls book by the way and
I recommend you get it if you don't already. It's got a lot of stuff in
there and although personally I don't think he explains things clearly as to
why things work as they do, it's still an invaluable resource for control
developers and everyone should own a copy. The only problem so far is for
design-time support and I'm still devising a way to do this.

Well, good luck.
Jiho
 
A

Antonio Bakula

Does anyone know if it is possible to emit a imagebutton with a bitmap
within a custom control.
In other words; I want the custom control to be selfcontained, and not have
to rely on a aspx page to be able to display an imagebutton with a
dynamically stored image. (From a database or loaded from a resource file.)

All I can find is this:

(...)
MemoryStream tempStream = new MemoryStream();

bitmap.Save(Page.Response.OutputStream,ImageFormat.Gif );

But then I am relying on a separate aspx page as a source for my
imagebutton.

Anyone knows any good techniques?


I have created TStreamImage class that is descendant from
System.Web.UI.WebControls.Image, this class adds functionality to read
image from memory stream. Control works in design time also, but only in
VS.NET and Delphi .NET, well almost working ;)

Control uses http module, when user assigns MemoryStream to control, stream
is stored and fake url is generated, then in normal rendering of web page
image itself generates another request with this fake url, and http module
intercepts this request, streams back saved image to the browser and ends
http request. Only thing that you (or user of this control) had to do is
register http module in web.config of current web application.

Control will try to add it's module in design time, i had *LOT OF* problems
with this one, specially getting the path of web.config in design time. So
be sure to check if web.config is configured properly.

Since I don't like to solve same problem again and again ;) I created
separate assembly to deal with registering HttpModule.

You can download these controls with source code and some additional
readme. Be warned that this code is still under *heavy* development and I
will really like to hear some comments, and specially any improvements of
this code or idea.

Code is written in Delphi, but there are some example projects that use
this controls in c#

You can download it from :

http://baksa.europe.webmatrixhosting.net/

As you can read my English is not very best, sorry :)
 
B

bobben

I figured it out....sort of.... It seems that this can be solved using the
tag:
<img src="data:image/gif;base64,'.<base64encodedImageString>.'

This is however only supported by 4.01 compliant browsers (or something
like that) AND IE is not compliant.

Great! I see that this is supported in ASP.Net 2.0 with the Webresource
feature.... just have to wait.



Thanks anyway!
Børge
 
J

Jiho Han

That's great.

BTW, can you point me at the resource where you found base64 stuff?
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top