Friday, July 30, 2010

Making a custom container control in ASP.Net (without templates)

If you're anything like me, you've tried to make your own ASP.Net server control that had container functionality, but were greeted with this exception when parsing:

"Type 'YourControlHere' does not have a public property named 'SomeHtmlElement'."

Next you goggled all possible permutations of "asp.net server control tutorial" and "child controls". Most of the solutions seemed to be either, "call EnsureChildControls", or "Use a template". However, you already called "EnsureChildControls", and if the ASP Panel control doesn't use a template, why would you?

To fix this inconvenience simply put the following attribute before your control class:
[ParseChildren(false)]

Now you are free to go about your business calling this.RenderChildren where ever and when ever you please!

Thursday, July 8, 2010

Problems with Telerick RadGrids inside a dynamic element?

I was working on a drag and drop system yesterday, but I had some problems in Firefox. When containers resized, the Telerick RadGrids inside of them would overflow instead of resizing properly like they do in IE8 (weird I know) and Chrome.

My first attempt at a work around was to allow dynamic resizing in the server-side RadGrid options. This was effective; however, it had the unfortunate, but not completely unexpected side-effect of allowing users to resize and distort the grid. Although, the main benefit of trying this fix was examining the resulting DOM and discovering an more effective solution:
<MasterTableView TableLayout="Fixed" />
When the table-layout style attribute of the table is changed from "auto" to "fixed" the problem seems to disappear.

It would not surprise me if there was a better solution to the problem out there; I can't claim to be an expert with Telerick controls. All the same, I hope someone finds the information in this post helpful.