System.Web.UI.Design.ControlDesigner never calls GetErrorDesignTimeHtml on Exceptions

J

John Saunders

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
(e-mail address removed)
 
V

Victor Garcia Aprea [MVP]

Hi John,
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.
 
J

John Saunders

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
(e-mail address removed)

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

Victor Garcia Aprea [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top