Server control that renders images

Discussion in 'ASP .Net Building Controls' started by Stephen Walch, Apr 23, 2004.

  1. Trying to think through how to create a server control (or user control)
    that renders some HTML plus any needed images. The rendered HTML would
    include IMG tags with URLs that point back to the same page in such a way
    that my server control would have a chance to render the image as well.
    There are plenty of examples of dynamic image rendering that use a PageLoad
    event or HttpHandler (ASHX page) but I can not figure out how to contain
    everything in one server control. Any suggestions or pointers to samples
    would be much appreciated.

    Thanks,
    - Steve
     
    Stephen Walch, Apr 23, 2004
    #1
    1. Advertisements

  2. Stephen Walch

    Teemu Keiski Guest

    Hi,

    The original problem is like you described, that images are requested
    separately and you need to have something that handles the request (usually
    it is an HttpHandler or Page etc). So to speak, it should be the same page
    that your control is on, that should handle the request (like you described)
    i.e IMG tags having URLs pointing back. Probably one way is to specify the
    IMG tag URL with a querystring parameter(s) which tell enough details to
    image rendering to take up the request processing. This would be detected in
    Page_Load, and when such condition is met, a certain method of the original
    control on the Page would be called.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke


    Trying to think through how to create a server control (or user control)
    that renders some HTML plus any needed images. The rendered HTML would
    include IMG tags with URLs that point back to the same page in such a way
    that my server control would have a chance to render the image as well.
    There are plenty of examples of dynamic image rendering that use a PageLoad
    event or HttpHandler (ASHX page) but I can not figure out how to contain
    everything in one server control. Any suggestions or pointers to samples
    would be much appreciated.

    Thanks,
    - Steve
     
    Teemu Keiski, Apr 23, 2004
    #2
    1. Advertisements

  3. Stephen Walch

    Teemu Keiski Guest

    And to add to the previous, this "rendering case" of course could be
    detected/done inside the control as well. You could do it in overridden
    OnInit or OnLoad methods, so that the logic could be contained in the
    control.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke


    Trying to think through how to create a server control (or user control)
    that renders some HTML plus any needed images. The rendered HTML would
    include IMG tags with URLs that point back to the same page in such a way
    that my server control would have a chance to render the image as well.
    There are plenty of examples of dynamic image rendering that use a PageLoad
    event or HttpHandler (ASHX page) but I can not figure out how to contain
    everything in one server control. Any suggestions or pointers to samples
    would be much appreciated.

    Thanks,
    - Steve
     
    Teemu Keiski, Apr 23, 2004
    #3
  4. OK, If I do the rendering from my control as you describe, how can I make
    sure that ONLY my control (and nothing else on the page) responds to certain
    Query strings?
     
    Stephen Walch, Apr 23, 2004
    #4
  5. Stephen Walch

    Teemu Keiski Guest

    Well,

    in strict sense you can't as query strings are global for entire request,
    but certainly if you do the checking it in say OnInit (of the control), it
    is unlikely that anything else has something going by that time. And you can
    call HttpApplication.CompleteRequest to end the request processing after
    control has done its job.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke

    OK, If I do the rendering from my control as you describe, how can I make
    sure that ONLY my control (and nothing else on the page) responds to certain
    Query strings?
     
    Teemu Keiski, Apr 24, 2004
    #5
  6. The way I deal with this is to have the Image resources for my custom
    controls embedded in the DLL (of the Class Library, not a part of the site).
    I have created an HttpHandler to handle the requests and configured the IIS
    Application to send requests for .ERES to my handler. I can then use a path
    to the DLL specially formatted URL to access any image resource. This works
    extremely well for packaging up you images (or any content including .js
    files) for distribution but has a small issue with design visibility that I
    am currently working on.

    I have attached all the code for the handler to this message and the
    following code is how you would use it:

    string urlString =
    HttpHandlers.HttpEmbeddedResourceHandler.GetResourceURL(this.Context,
    this.GetType().Assembly, "Controls/Images/UpdateButton.gif");

    The UpdateButton.gif file in the project is in the Controls/Images directory
    and it's "Build Action" is set to Embedded Resource.

    Hope this all helps!

    Fred

    ----- Following is the comment on the attached source file...
    This HttpHandler is used to extract embedded resources for controls. There
    are a couple of configuration
    settings that must be done before an application can actually use the
    controls (to use the embedded
    resources).

    1) The Web Application must be configured (using IIS console) to have an
    additional mapping under the
    configuration tab. Add a new mapping that has the "aspnet_isapi.dll" as
    the executable and .eres as the
    file extension. Make sure to unselect the "Check that file exists"
    checkbox as these files do not actually
    exist.
    2) Add the following mapping to the web.config file under <system.web>
    <httpHandlers>
    <add verb="*" path="*.eres"
    type="SierraSystems.Web.HttpHandlers.HttpEmbeddedResourceHandler,
    SierraSystems.Web"
    validate="true" />
    </httpHandlers>

    Controls can now create a URL to the embedded resources, the format of the
    URL is:
    http://webserver/appname/[AssemblyName]/[ResourcePath].eres

    EG:
    http://webserver/app/SierraSystems.Web/Controls/Images/AddButton.gif.eres
     
    Fred Hirschfeld, Apr 25, 2004
    #6
  7. Stephen Walch

    Teemu Keiski Guest

    Yeah, that is the preferred way. Original poster however asked how to do
    that all with a server control, so I thought he had considered HtttpHandler
    option already.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke


    The way I deal with this is to have the Image resources for my custom
    controls embedded in the DLL (of the Class Library, not a part of the site).
    I have created an HttpHandler to handle the requests and configured the IIS
    Application to send requests for .ERES to my handler. I can then use a path
    to the DLL specially formatted URL to access any image resource. This works
    extremely well for packaging up you images (or any content including .js
    files) for distribution but has a small issue with design visibility that I
    am currently working on.

    I have attached all the code for the handler to this message and the
    following code is how you would use it:

    string urlString =
    HttpHandlers.HttpEmbeddedResourceHandler.GetResourceURL(this.Context,
    this.GetType().Assembly, "Controls/Images/UpdateButton.gif");

    The UpdateButton.gif file in the project is in the Controls/Images directory
    and it's "Build Action" is set to Embedded Resource.

    Hope this all helps!

    Fred

    ----- Following is the comment on the attached source file...
    This HttpHandler is used to extract embedded resources for controls. There
    are a couple of configuration
    settings that must be done before an application can actually use the
    controls (to use the embedded
    resources).

    1) The Web Application must be configured (using IIS console) to have an
    additional mapping under the
    configuration tab. Add a new mapping that has the "aspnet_isapi.dll" as
    the executable and .eres as the
    file extension. Make sure to unselect the "Check that file exists"
    checkbox as these files do not actually
    exist.
    2) Add the following mapping to the web.config file under <system.web>
    <httpHandlers>
    <add verb="*" path="*.eres"
    type="SierraSystems.Web.HttpHandlers.HttpEmbeddedResourceHandler,
    SierraSystems.Web"
    validate="true" />
    </httpHandlers>

    Controls can now create a URL to the embedded resources, the format of the
    URL is:
    http://webserver/appname/[AssemblyName]/[ResourcePath].eres

    EG:
    http://webserver/app/SierraSystems.Web/Controls/Images/AddButton.gif.eres
     
    Teemu Keiski, Apr 25, 2004
    #7
  8. you can use TStreamImage for image rendering, or look at it's source
    (Delphi.NET). TStreamImage is free control, url :

    http://www.antoniob.com/projects/PStreamImage.aspx

    That is basically Image descendant that have memorystream as source for
    image, all in one server control. you can read more about it on url above.
     
    Antonio Bakula, Apr 26, 2004
    #8
  9. Hi Stephen,

    Does the community's reply make sense to you?

    In asp.net, there are another way of dynamically generate image. This way,
    you may change an assistant page's ContentType to "image/jpeg", then you
    can use GDI+ drawing image and output to the assistant page OutputStream.
    Then, to use it, you may place a <img> tag, which point to this assistant
    page.

    For more information, please refer to:
    "Create Snazzy Web Charts and Graphics On the Fly with the .NET Framework"
    http://msdn.microsoft.com/msdnmag/issues/02/02/ASPDraw/default.aspx

    Also, these 2 articles also may give you useful information about this
    technology.

    Thank you for your patience and cooperation. If you have any questions or
    concerns, please feel free to post it in the group. I am standing by to be
    of assistance.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Jeffrey Tan[MSFT], Apr 29, 2004
    #9
  10. Jeffrey Tan[MSFT], Apr 29, 2004
    #10
  11. Hi Stephen,

    Does my reply make sense to you? Do you still have any concern on this
    issue?

    Please feel free to feedback. Thanks

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Jeffrey Tan[MSFT], May 3, 2004
    #11
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.