Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

custom web control in asp data grid

i built two very simple custom web controls: SafeLabel and SafeHyperlink. They merely override the render methods of Label and Hyperlink to htmlencode the values to prevent script injection attacks and related bugs. (Why label doesn't do this by default, with a second control called HtmlOutput or something is beyond me.)

Anyway, this works perfectly. I even added a designer so it renders in visual studio's design mode. (Couldn't figure out how to get the default designer to run right.). But with or without the designer class, if I use one of my controls in a datagrid template column, the following error shows up in the IDE's designer:

Datagrid - gridname
There was an error rendering the control. Check to make sure all properties are valid.

Anyone seen this? Not much about it found by google. It works fine running the app itself, which is what counts.

mb
Wednesday, September 24, 2003

Some source would help out here... I've been able to use custom controls inside datagrids w/o a problem.

Greg Hurlman
Thursday, September 25, 2003

Definately looks like a bug in the datagrid. Easy enough to workaround, but definately a bug.

My control inherits System.Web.UI.WebControls.HyperLink. It has one method, Render, which sets the text to this.Context.Server.HtmlEncode(this.Text), calls base.Render, then reverts the text to the previous value.

This does not work in the designer. But no problem, I have a 'designer' class, which calls System.Web.HttpUtility.HtmlEncode on the text.

This works just fine if I drop my safeHyperlink on the page. But if it's in a templated column, the datagrid calls Render, which fails.

Workaround? I might use the HttpUtility instead of the HttpServerUtility. Anyone know if there's any perf difference there?
I could also catch an exception or otherwise bloat the render code to handle this case, but that's probably not worth it.

mb
Friday, September 26, 2003

I also get this exact problem with the exact same circumstances with VS.Net 2002.  I've even reduced the Designer class to simply returning an simple string and it still gives the error you mentioned.

I would be very glad for any input that anyone might have.

Thanks,
Payton Byrd
http://www.paytonbyrd.com

Payton Byrd
Friday, September 10, 2004

*  Recent Topics

*  Fog Creek Home