Groups | Blog | Home
all groups > asp.net building controls > july 2003 >

asp.net building controls : System.Web.UI.Design.ControlDesigner never calls GetErrorDesignTimeHtml on Exceptions


John Saunders
7/31/2003 7:52:44 PM
I can create a reproducer for this later, if needed, but I'm too aggravated
at the moment.

I have a control whose GetDesignTimeHtml method pretty much just calls
base.GetDesignTimeHtml(). ControlDesigner.GetDesignTimeHtml of course, calls
((Control) component).Render(htmlStringWriter) and then returns the string.

Recently, the Render method of this control gained some code which throws an
exception. Apparently, ControlDesigner.GetDesignTimeHtml catches this
exception - and takes it as an excuse to call this.GetEmptyDesignTimeHtml().

I've got a try-catch block around my call to base.GetDesignTimeHtml, so if
ControlDesigner.GetDesignTimeHtml had even failed to handle the exception,
I'd have picked it up and displayed something useful. Instead, I got a
useless placeholder saying "Please set some parameters". It continues saying
"Please set some parameters" even after I set the parameters, which is quite
frustrating.


Could this be fixed, if it's a bug, or documented, if it's a feature, or
explained, if I missed something?

Thanks,
John Saunders
Internet Engineer
john.saunders@surfcontrol.com

Victor Garcia Aprea [MVP]
8/4/2003 12:44:53 AM
Hi John,

[quoted text, click to view]
string.

Actually it does a bit more:

a) it will call RenderControl (note, not Render), then, if any exceptions
were thrown it will call GetErrorDesignTimeHtml (which by default returns an
empty string).
b) if it still has an empty string as the html it will call
GetEmptyDesignTimeHtml.

Per your description it seems like:

1) your control is throwing an exception in Render thus causing the control
designer to call GetErrorDesignTimeHtml
2) you're not overriding GetErrorDesignTimeHtml, so the default
implementation will return an empty string
3) as the control designer can't still get a non-emtpy string, after having
tried your control's RenderControl method and calling
GetErrorDesignTimeHtml, it will finally call GetEmptyDesignTimeHtml.

Please try overriding GetErrorDesignTimeHtml and let me know if that helps,


--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.

[quoted text, click to view]

John Saunders
8/4/2003 8:46:19 AM
Victor, you've got it.

The designer for that control had been derived from my
CompositeControlDesigner. But then I added template functionality and
changed it to derive from my BaseTemplatedDesigner, which did not contain
the Get*DesignTimeHtml methods. In the absence of multiple inheritance, I
had to copy everything interesting from CompositeControlDesigner into the
derived designer. And I missed GetErrorDesignTimeHtml!

Thanks!
John Saunders
Internet Engineer
john.saunders@surfcontrol.com

P.S. You should send your response to Microsoft Framework Documentation. You
could save them (and posterity) a lot of work.

[quoted text, click to view]

Victor Garcia Aprea [MVP]
8/4/2003 11:12:07 PM
No problem, glad its working now!

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.

[quoted text, click to view]

AddThis Social Bookmark Button