Composite Control Designer Question

S

Showjumper

I have built a composite control that consists of a textbox and a button
that performs a whois lookup. How do i get the control to update its
appearance when in design view of a webform after a property has been
changed. I assume it has to do with creating a composite control designer
which i think i have done. Right now i am trying to just get the button text
to update once the property is changed. Any help is appreciated...

Ashok


The whoisdesigner class is below and i have <DefaultProperty("ButtonText"),
ToolboxData("<{0}:WhoIsLookup runat=server></{0}:WhoIsLookup>"),
Designer(GetType(WhoIsDesigner))> Public Class WhoIsLookup
'rest of the code is here

Public Class WhoIsDesigner
Inherits ControlDesigner
Dim WhoIsInstance As WhoIsLookup
Public Sub New()
End Sub 'New
Public Overrides Sub Initialize(ByVal component As
System.ComponentModel.IComponent)
Me.WhoIsInstance = CType(component, WhoIsLookup)
MyBase.Initialize(component)
End Sub 'Initialize
Public Overrides Function GetDesignTimeHtml() As String
Try
Dim sw As New StringWriter
Dim writer As New HtmlTextWriter(sw)
Dim SubmitButton As New Button

SubmitButton.Text = WhoIsInstance.ButtonText
WhoIsInstance.RenderControl(writer)
Return sw.ToString
Catch ex As Exception
Return Me.GetErrorDesignTimeHtml(ex)
End Try

End Function
End Class
 
R

recoil

That is extremely different from the way I build my controls. I usually
build a single class that is my BaseDesinger which inherits from
ControlDesigner.

in the GetDesignTimeHtml i build a new StringWriter and then i build a
new HtmlTextWriter passing the newly constructed StringWriter.
The variable Component contains the control that the Designer is
responsible for so I typecast Component to Control and then call the
RenderControl method with WriteHtml.

This way all of your Control Creation and logic is kept in your
WebControl which usually inherits from WebControl.
I put Put all of my Control Creatin in the Control's onInit. and all of
the Rendering in the Render both of which are overriden.

Then I just slap this on top of the class right next to the ToolboxData
property
[Designer("Bleah.WebSupport.Internal.Designers.BaseDesigner")]
where the whole thing is your Namespace.Designer class.

And fore the most part when ever this method is used the control is
usually updated when ever a property is changed.

http://www.dotnet247.com/247reference/msgs/51/258702.aspx
this post contains a bit of useful information but I think alot of your
problems might be solved if you implement the Control and the Designer
as 2 seperate items and not try using a ControlDesigner as your
Control.
 

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,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top