Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Server control that renders images

Reply
Thread Tools

Server control that renders images

 
 
Stephen Walch
Guest
Posts: n/a
 
      04-23-2004
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


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      04-23-2004
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



 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      04-23-2004
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



 
Reply With Quote
 
Stephen Walch
Guest
Posts: n/a
 
      04-23-2004
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
>
>
>



 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      04-24-2004
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
>
>
>




 
Reply With Quote
 
Fred Hirschfeld
Guest
Posts: n/a
 
      04-25-2004
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.GetResour ceURL(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.HttpEmbeddedR esourceHandler,
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.W...utton.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
> >
> >
> >

>
>
>





 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      04-25-2004
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.GetResour ceURL(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.HttpEmbeddedR esourceHandler,
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.W...utton.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
> >
> >
> >

>
>
>





 
Reply With Quote
 
Antonio Bakula
Guest
Posts: n/a
 
      04-26-2004
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:

 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      04-29-2004
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/is...w/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.

 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      04-29-2004
Sorry, the 2 articles links are:
"3D Pie Chart in ASP.NET"
http://www.codeproject.com/aspnet/3dpiechart.asp

"ASP.NET Controls to prevent automatic registrations from bots"
http://www.codeproject.net/aspnet/antiauto.asp

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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Control Half-Renders gordonta ASP .Net 0 03-23-2009 03:15 PM
User Control Renders on Separate Line jdp ASP .Net 5 08-08-2006 03:00 PM
Custom control renders table but doesn't resize at design time. Chubby Arse ASP .Net 0 10-06-2005 10:18 AM
Server control that renders images Stephen Walch ASP .Net Web Controls 1 04-24-2004 08:20 AM



Advertisments