GetDesignTimeHTML doesn't fire for PanelDesigner.

S

Steve Wesorick

I have a custom web control that inherits from
System.Web.UI.WebControls.Panel

What I want is for developers to be able to drag controls from the
toolbox, into my control, and have them appear as they would on the
finished page. My control renders a table around the outside of its
child controls, and puts a special header row at the beginning of this
table.

for example:
<cc1:myctl id=myctl1 runat=server text="sometext!"
imageURL="mygif.gif"><span>some content and child
controls</span></cc1:myctl>

comes out at run time as:
<table>
<tr>
<td><img src="mygif.gif">sometext!</td>
</tr>
<tr>
<td><span>some content and child controls</span></td>
</tr>
</table>

If I inherit System.Web.UI.Design.ControlDesigner as my designer, I
can override the GetDesignTimeHTML function, and get everything to
render correctly at design time. However, you cannot click on the
child controls, or drag controls from the toolbox onto my custom
control that way.

If I inherit System.Web.UI.Design.WebControls.PanelDesigner
as my designer, then I can drag and drop controls from the toolbox,
and click on them to edit them, etc. However, I can't figure out how
to get my custom html to wrap around the design-time control. (At run
time everything is fine) I've tried overriding the GetDesignTimeHTML
function, but it doesn't seem to be firing.
 
V

Victor Garcia Aprea [MVP]

Hi Steve,

What you're experiencing its by design. When ReadOnly property is set to
true (default in ControlDesigner) you can't drag & drop controls and
GetDesignTimeHTML will be called. Instead, when ReadOnly is set to false
(which is set in ReadWriteControlDesigner.ctor) GetDesignTimeHTML wont be
called.

--
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
 
S

Steve Wesorick

Thanks, Victor. That is helpful to know. It gives me some ideas
about alternative ways to proceed with this.

The thing that got me wondering about is that something is rendering a
DIV tag (Or something similar) around my read-write control at design
time. I can tell, because if I set the Backcolor of my control (Since
it inherits from Panel) the backcolor of the control changes, and all
of the child controls have a color behind them at design time. What I
would like to do is override this so that instead of writing a
<DIV>...ChildControls...</DIV> it writes something more like
<table><TR><TD>MyCustomStuff</td></tr><tr><td><DIV>...ChildControls...</DIV></td></tr></table>
at design time. Is there another rendering function I can override to
accomplish this?

An alternative might be to give the developer the option to switch
between ReadOnly and Read-Write modes at design time. Maybe by double
clicking on the control, or via a context menu (Similar to the way you
edit a Template Column in a Data Grid Control).

Does anyone know how to add a context menu to a control designer? Or
how you go about capturing the double click event? Both of these
would also be helpful in future component designs.


Thanks again!
-Steve
 
S

Steve Wesorick

OK, so I figured out how to add a context menu to my control designer:

Public Sub New()
MyBase.new()
Me.Verbs.Add(New
System.ComponentModel.Design.DesignerVerb("Change Read Only", AddressOf
EditFilterOptions))
End Sub

Public Sub EditFilterOptions(ByVal sender As Object, ByVal e As
EventArgs)
Me.ReadOnly = not Me.ReadOnly
End Sub


Now the problem is that changing the value of the "ReadOnly" property
doesn't seem to do anything, unless it happens in the Sub New(). How do
I notify my control designer that the ReadOnly Propery has changed, so
that I can switch my control from drag and drop mode, to full display
mode?

I've tried setting me.IsDirty to true, and calling me.Initialize, and
me.InitializeNonDefault, but none of them seem to do the trick.
 

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

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top