Altering Design-time html of custom control

E

Eidolon

I have written my own class deriving from WebControl. The HTML that the
control puts out is such that it is not visible to the user, including in
design time. I am trying to add a ControlDesigner to my class, which would
put a visual bit out at design-time, similar to the grey box the designer
puts out when it encounters an error creating a control, just for
visibility, and so you can select the control by clicking on it.
It does not seem to work though. The control works fine, but the visual
design part doesnt show up.

Any help appreciated. Thanks!

Code follows:

Public Class ClientFormDesigner
Inherits System.Web.UI.design.ControlDesigner

Public Overrides Function GetDesignTimeHtml() As String
Dim html As String = "<div style='width: 100px; height: 30px;
border: solid 2px; outset; background-color: black;'>?</div>"
html = html.Replace("?", MyBase.ID & "<br>" &
MyBase.GetDesignTimeHtml)
Return html
End Function
End Class

<DesignerAttribute(GetType(Designers.ClientFormDesigner),
GetType(IDesigner)), DefaultProperty("Action"), ToolboxData("<{0}:ClientForm
runat=server></{0}:ClientForm>")> Public Class ClientForm
Inherits System.Web.UI.WebControls.WebControl

[ properties ommited for brevity ]

Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
[ custom render code here. works fine ]
End Sub
End Class
 
A

Alessandro Zifiglio

You need to override the GetEmptyDesignTimeHtml() function in your designer
and return this in your GetDesignTimeHtml() function.


'The GetDesignTimeHtml method returns design-time HTML for a control.
'The base implementation of GetDesignTimeHtml invokes the Render
'method of the control, thereby rendering the same HTML at
'design time as at run time. The task of the designer is to override
'GetDesignTimeHtml so as to render HTML that is more appropriate at design
time

Public Overrides Function GetDesignTimeHtml() As String
Dim designTimeHTML As String = Nothing

designTimeHTML = GetEmptyDesignTimeHtml()

Return designTimeHTML
End Function


'The GetEmptyDesignTimeHtml method supplies an HTML string to
'render at design time if the run-time HTML string rendered by the control
'is empty, such as when properties are not set. The base implementation of
'the GetEmptyDesignTimeHtml method returns the fully
'qualified name and ID of the control. A designer can override this
'method and invoke CreatePlaceHolderDesignTimeHtml,
'or it can return alternate HTML.
'In our case we wont use it :)

Protected Overrides Function GetEmptyDesignTimeHtml() As String
Dim _text As String
_text = "This is the No.1 Invisible control"
Return CreatePlaceHolderDesignTimeHtml(_text)
End Function



'The GetErrorDesignTimeHtml method provides the HTML to be used
'for the design-time representation of the
'control when an error is encountered.

Protected Overrides Function GetErrorDesignTimeHtml(ByVal e As
Exception) As String
Return CreatePlaceHolderDesignTimeHtml("There was an error
rendering the control.<br>Check to make sure all properties are valid.")
End Function
Eidolon said:
I have written my own class deriving from WebControl. The HTML that the
control puts out is such that it is not visible to the user, including in
design time. I am trying to add a ControlDesigner to my class, which would
put a visual bit out at design-time, similar to the grey box the designer
puts out when it encounters an error creating a control, just for
visibility, and so you can select the control by clicking on it.
It does not seem to work though. The control works fine, but the visual
design part doesnt show up.

Any help appreciated. Thanks!

Code follows:

Public Class ClientFormDesigner
Inherits System.Web.UI.design.ControlDesigner

Public Overrides Function GetDesignTimeHtml() As String
Dim html As String = "<div style='width: 100px; height: 30px;
border: solid 2px; outset; background-color: black;'>?</div>"
html = html.Replace("?", MyBase.ID & "<br>" &
MyBase.GetDesignTimeHtml)
Return html
End Function
End Class

<DesignerAttribute(GetType(Designers.ClientFormDesigner),
GetType(IDesigner)), DefaultProperty("Action"), ToolboxData("<{0}:ClientForm
runat=server></{0}:ClientForm>")> Public Class ClientForm
Inherits System.Web.UI.WebControls.WebControl

[ properties ommited for brevity ]

Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
[ custom render code here. works fine ]
End Sub
End Class
 

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,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top