Server control that renders images

S

Stephen Walch

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
 
T

Teemu Keiski

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
 
T

Teemu Keiski

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
 
S

Stephen Walch

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

Teemu Keiski

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

Fred Hirschfeld

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
 
T

Teemu Keiski

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
 
A

Antonio Bakula

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

Jeffrey Tan[MSFT]

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

Jeffrey Tan[MSFT]

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.
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top