Image within a custom control

Discussion in 'ASP .Net Building Controls' started by bobben, Feb 4, 2004.

  1. bobben

    bobben Guest

    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
     
    bobben, Feb 4, 2004
    #1
    1. Advertising

  2. bobben

    Jiho Han Guest

    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

    "bobben" <> wrote in message
    news:...
    > 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
    >
    >
     
    Jiho Han, Feb 4, 2004
    #2
    1. Advertising

  3. On Wed, 4 Feb 2004 11:27:33 +0100, bobben wrote:

    > 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 :)

    --
    !Antonio
    remove XremoveX from e-mail address
    AntiSpam Fodder:
     
    Antonio Bakula, Feb 5, 2004
    #3
  4. bobben

    bobben Guest

    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

    "Antonio Bakula" <> wrote in message
    news:j3bc25qsgeei$.fqd4hxcdhl2p$...
    > On Wed, 4 Feb 2004 11:27:33 +0100, bobben wrote:
    >
    > > 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 :)
    >
    > --
    > !Antonio
    > remove XremoveX from e-mail address
    > AntiSpam Fodder:
    >
     
    bobben, Feb 6, 2004
    #4
  5. bobben

    Jiho Han Guest

    That's great.

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

    "bobben" <> wrote in message
    news:...
    > 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
    >
    > "Antonio Bakula" <> wrote in message
    > news:j3bc25qsgeei$.fqd4hxcdhl2p$...
    > > On Wed, 4 Feb 2004 11:27:33 +0100, bobben wrote:
    > >
    > > > 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 :)
    > >
    > > --
    > > !Antonio
    > > remove XremoveX from e-mail address
    > > AntiSpam Fodder:
    > >

    >
    >
     
    Jiho Han, Feb 6, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonah Olsson
    Replies:
    1
    Views:
    611
    Scott Allen
    Apr 5, 2005
  2. =?Utf-8?B?SmF5YnVmZmV0?=
    Replies:
    9
    Views:
    865
    Phillip Williams
    Feb 21, 2006
  3. J R M
    Replies:
    2
    Views:
    453
    Charlie@CBFC
    Jun 1, 2006
  4. Matt Sokol
    Replies:
    2
    Views:
    427
    Theo Tillotson
    Aug 7, 2003
  5. Jonah Olsson
    Replies:
    2
    Views:
    218
    Jonah Olsson
    Apr 5, 2005
Loading...

Share This Page