custom WebControl sometimes doesn't render at design time
I've created quite a few WebControls with pretty good success. I've
made designers, data-bound controls, and so on. (Thank you to Nikhil
Kothari and Vandana Datye for "Developing Microsoft ASP.NET Server
Controls and Components".) I'm pretty comfortable with them now.
However, occasionally, some of the simple composite controls do not get
rendered at design time. All that shows up is the litte green boxed
triangle placeholder icon that the VS.NET designer puts in the top left
corner of all server controls. The control still shows up in the
property browser, and there are no errors displayed. The control always
renders property at run time. What's more, if I have several controls
on a designer, some will render, and some won't.
My GetDesignTimeHtml method usually looks something like this:
Public Overrides Function GetDesignTimeHtml() As String
Dim field As BaseField = CType(Component, BaseField)
Dim controls As ControlCollection = field.Controls
Dim html As String
Dim wasBlank As Boolean = field.Text.Length = 0
If field.ReadOnly And wasBlank Then
field.Text = "[Value]"
html = MyBase.GetDesignTimeHtml
Catch ex As Exception
html = MyBase.GetErrorDesignTimeHtml(ex)
If wasBlank Then
field.Text = String.Empty
Has anyone else seen this happen and knows what causes it?
Re: custom WebControl sometimes doesn't render at design time
(MAN I hate it when I FINALLY decide to send a question to the group,
only to figure out the answer moments later.)
This was my bug. The reason the control was not showing up was that due
to an initial state of a private member, I was not executing the
majority of the code in the Render method. What I should have done was
call the public Property that returns the proper initial value for that
private member.... (slaps forehead).
|All times are GMT. The time now is 05:30 PM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.