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. Advertising

  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


    "Stephen Walch" <> wrote in message
    news:...
    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. Advertising

  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


    "Stephen Walch" <> wrote in message
    news:...
    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?

    "Teemu Keiski" <> wrote in message
    news:%233iK4%...
    > 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
    >
    >
    > "Stephen Walch" <> wrote in message
    > news:...
    > 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
    #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

    "Stephen Walch" <> wrote in message
    news:u$...
    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" <> wrote in message
    news:%233iK4%...
    > 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
    >
    >
    > "Stephen Walch" <> wrote in message
    > news:...
    > 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 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



    "Teemu Keiski" <> wrote in message
    news:%...
    > 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
    >
    > "Stephen Walch" <> wrote in message
    > news:u$...
    > 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" <> wrote in message
    > news:%233iK4%...
    > > 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
    > >
    > >
    > > "Stephen Walch" <> wrote in message
    > > news:...
    > > 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
    > >
    > >
    > >

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


    "Fred Hirschfeld" <> wrote in message
    news:...
    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" <> wrote in message
    news:%...
    > 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
    >
    > "Stephen Walch" <> wrote in message
    > news:u$...
    > 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" <> wrote in message
    > news:%233iK4%...
    > > 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
    > >
    > >
    > > "Stephen Walch" <> wrote in message
    > > news:...
    > > 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 25, 2004
    #7
  8. On Fri, 23 Apr 2004 15:35:36 -0400, Stephen Walch wrote:

    > 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.
    >


    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.

    --
    http://www.antoniob.com/
    remove XremoveX from e-mail address
    AntiSpam Fodder:
     
    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. 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. Chubby Arse
    Replies:
    0
    Views:
    578
    Chubby Arse
    Oct 6, 2005
  2. jdp
    Replies:
    5
    Views:
    341
  3. gordonta

    Control Half-Renders

    gordonta, Mar 23, 2009, in forum: .NET
    Replies:
    0
    Views:
    369
    gordonta
    Mar 23, 2009
  4. Zarko Gajic

    Child control renders at desing-time as if it is in run-time...

    Zarko Gajic, Mar 14, 2005, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    149
    Zarko Gajic
    Mar 16, 2005
  5. Stephen Walch

    Server control that renders images

    Stephen Walch, Apr 23, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    106
    Kevin Yu [MSFT]
    Apr 24, 2004
Loading...

Share This Page