[snip]
> Public myButton As New Button()
You should declare this as a read-only property and be sure to call
EnsureChildControls() before accessing it:
Dim _MyButton As Boolean
Public Property MyButton() As Boolean
Get
EnsureChildControls()
Return _MyButton
End Get
End Property
> Protected Overrides Sub CreateChildControls()
> With myButton
> .Text = "Click Me!"
> .Visible = False
> End With
> Controls.Add(myButton)
> End Sub
This is where you should *create* the child controls, not initialize them:
Protected Overrides Sub CreateChildControls()
_MyButton = New Button()
With _MyButton
.Text = "Click Me!"
.Visible = False
End With
Controls.Add(_MyButton)
End Sub
> Private Sub ButtonControl_PreRender(ByVal sender As Object,
> ByVal e As System.EventArgs) Handles MyBase.PreRender
> If bMyButton Then
> myButton.Visible = True
> Else
> myButton.Visible = False
> End If
> End Sub
Why use an internal variable? Why not just read/write directly to
MyButton.Visible for the ShowMyButton property?
Example:
<Browsable(True), DefaultValue(False)>
Public Property ShowMyButton() As Boolean
Get
Return MyButton.Visible
End Get
Set(ByVal Value As Boolean)
MyButton.Visible = Value
End Set
End Property
You could then exclude the step of assigning _MyButton.Visible in your
CreateChildControls method:
Protected Overrides Sub CreateChildControls()
_MyButton = New Button()
With _MyButton
.Text = "Click Me!"
End With
Controls.Add(_MyButton)
End Sub
--
-Jimmy
Used-Disks:
http://www.used-disks.com/