Project Description
This project contains a Web Custom Control for rendering images directly from the database. Can be used with image fields, with text, date or number fields (it generates an image containing the text) and also with URL fields (like a usual image control).

To test this control:
  • Open or create a website.
  • Add the VSCustomRendererLibrary reference to the website.
  • Add the following line in <httpHandlers> section in webconfig:
<add verb="*" path="*.jpg" type="VSCustomRendererLibrary.VsImageHandler, VSCustomRendererLibrary"/>

If you cannot find this section in your webconfig file, just create it under <system.web>:
<system.web>
......
<httpHandlers>
<add verb="*" path="*.jpg" type="VSCustomRendererLibrary.VsImageHandler, VSCustomRendererLibrary"/>
</httpHandlers>
</system.web>
  • Open/create a new aspx page.
  • Add a SqlDataSource connected to a table or a view (this project was tested with the SQL Server 2005 EE).
  • Add a gridview and connect it to the SqlDataSource.
  • In the gridview add the image column and transform it into a template field.
  • Select Edit Template from the gridview toolbar menu.
  • Add a VSCustomRenderer into the ItemTemplate. Bind the control to the datasource field.

[image:databind.gif]
Changes in v.3.0

This webcontrol now works with Ajax.
This controls no longer saves images to disk in order to display them. The pictures are displayed directly from memory through a IHttpHandler.
This http handler does not open a new database connection, it just displays the images from memory so there are no delays in page rendering and no extra parameters to set.

Properties removed

FolderToSaveImage
FilePrefix
UniqueIdValue

Changes in v.2.0
V.1.0 did not work on all systems. This version has been tested on Win XP SP2 x32 and Windows Vista x64.

Properties added:

FolderToSaveImage - the folder inside your site where generated images will be saved (default value is "./images/")

FilePrefix - this prefix will be added at the begining of the generated filenames

UniqueIdValue - you can bind this property to a unique id field. This property is used in composing the filenames. If no value is specified a new GUID will be generated for each new image.

The generated filenames will have this form FilePrefix UniqueIdValue (or GUID) ".gif"

To avoid hdd space problems, you can delete the generated images on the LoadComplete event of the page by calling the CleanFolder procedure on the control or by adding the code from this sub directly on this event.


You can bind:
  • ImageValue -> to a image field
  • TextToRender -> to a text/date/time/numeric field(this feature can be useful for rendering texts with special characters or for preventing e-mails or other contact data automatic collection)
  • PictureUrl -> to a field containing the url of a image file
  • UniqueIdValue - you can bind this property to a unique id field. This property is used in composing the filenames. If no value is specified a new GUID will be generated for each new image

Change these properties according to your project:
  • FolderToSaveImage - the folder inside your site where generated images will be saved (default value is "./images/")
  • FilePrefix - this prefix will be added at the begining of the generated filenames

adv2.jpg

Other properties are self-explanatory:
  • ImageWidth
  • ImageHeight
  • ImageBorderStyle
  • ImageBorderWidth
  • ImageBorderColor
  • ImageToolTip
  • AlternateText
  • TextBackgroundColor
  • TextForeColor
  • TextFont

This project was inspired by an article on code-project written by dev2dev: Article
Parts of the code were taken from that project.

Last edited Jul 5, 2008 at 7:27 PM by Florin_Florea, version 19