OK. Here's the code. I've never used a serialization attribute on any of my custom controls before....
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
<DefaultEvent("Logon"), DefaultProperty("UserID"), ToolboxData("<{0}:ctrlLogin runat=server></{0}:ctrlLogin>")> Public Class ctrlLogin
Inherits System.Web.UI.WebControls.WebControl
Implements INamingContainer
Private _UserID As String
Private _Password As String
Private _button As Button
Private _txtUserID As TextBox
Private _txtPassword As TextBox
Private _lblUserID As Label
Private _lblPassword As Label
Private _valUserID As RequiredFieldValidator
Private _valPassword As RequiredFieldValidator
#Region "Overridden Properties"
Public Overrides ReadOnly Property Controls() As ControlCollection
Get
EnsureChildControls()
Return MyBase.Controls()
End Get
End Property
#End Region 'Overriden Properties
#Region "Properties delegated to child controls"
<Bindable(True), Category("Appearance"), DefaultValue(""), Description("The text to display on the button")> _
Public Property ButtonText() As String
Get
EnsureChildControls()
Return _button.Text
End Get
Set(ByVal Value As String)
EnsureChildControls()
_button.Text = Value
End Set
End Property
<Bindable(True), Category("Default"), DefaultValue(""), Description("The User ID")> _
Public Property strUserID() As String
Get
EnsureChildControls()
Return _txtUserID.Text
End Get
Set(ByVal Value As String)
EnsureChildControls()
_txtUserID.Text = Value
End Set
End Property
<Bindable(True), Category("Appearance"), DefaultValue(""), Description("Error message of the validator used for the userID")> _
Public Property strUserID_ErrorMessage() As String
Get
EnsureChildControls()
Return _valUserID.ErrorMessage
End Get
Set(ByVal Value As String)
EnsureChildControls()
_valUserID.ErrorMessage = Value
_valUserID.ToolTip = Value
End Set
End Property
<Bindable(True), Category("Appearance"), DefaultValue(""), Description("The text for the userID label")> _
Public Property strUserID_Label() As String
Get
EnsureChildControls()
Return _lblUserID.Text
End Get
Set(ByVal Value As String)
EnsureChildControls()
_lblUserID.Text = Value
End Set
End Property
<Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Public ReadOnly Property strPassword() As String
Get
EnsureChildControls()
Return _txtPassword.Text
End Get
End Property
<Bindable(True), Category("Appearance"), DefaultValue(""), Description("Error message of the validator for the password")> _
Public Property strPasswordErrorMessage() As String
Get
EnsureChildControls()
Return _valPassword.ErrorMessage
End Get
Set(ByVal Value As String)
EnsureChildControls()
_valPassword.ErrorMessage = Value
_valPassword.ToolTip = Value
End Set
End Property
<Bindable(True), Category("Appearance"), DefaultValue(""), Description("The text for the password label")> _
Public Property strPasswordLabel() As String
Get
EnsureChildControls()
Return _lblPassword.Text
End Get
Set(ByVal Value As String)
EnsureChildControls()
_lblPassword.Text = Value
End Set
End Property
#End Region 'Properties delegated to child controls
#Region "Events"
<Category("Action"), Description("Raised when the user clicks the login button")> _
Event Logon(ByVal sender As Object, ByVal e As EventArgs)
Sub btnLogin_Clicked(ByVal source As Object, ByVal e As EventArgs)
RaiseEvent Logon(Me, e)
End Sub
#End Region 'Events
#Region "Overridden Controls"
Protected Overrides Sub CreateChildControls()
Controls.Clear()
_lblUserID = New Label
_txtUserID = New TextBox
_txtUserID.ID = "txtUserID"
_valUserID = New RequiredFieldValidator
_valUserID.ID = "valUserID"
_valUserID.ControlToValidate = _txtUserID.ID
_valUserID.Text = "*"
_valUserID.Display = ValidatorDisplay.Static
_lblPassword = New Label
_txtPassword = New TextBox
_txtPassword.TextMode = TextBoxMode.Password
_txtPassword.ID = "txtPassword"
_valPassword = New RequiredFieldValidator
_valPassword.ID = "valPassword"
_valPassword.ControlToValidate = _txtPassword.ID
_valPassword.Text = "*"
_valPassword.Display = ValidatorDisplay.Static
_button = New Button
_button.ID = "button1"
_button.CommandName = "Logon"
Me.Controls.Add(_lblUserID)
Me.Controls.Add(_txtUserID)
Me.Controls.Add(_valUserID)
Me.Controls.Add(_lblPassword)
Me.Controls.Add(_txtPassword)
Me.Controls.Add(_valPassword)
Me.Controls.Add(_button)
AddHandler _button.Click, AddressOf Me.btnLogin_Clicked
End Sub
Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
AddAttributesToRender(output)
output.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "1", False)
output.RenderBeginTag(HtmlTextWriterTag.Table)
'UserID line
output.RenderBeginTag(HtmlTextWriterTag.Tr)
output.RenderBeginTag(HtmlTextWriterTag.Td)
_lblUserID.RenderControl(output)
output.RenderEndTag()
output.RenderBeginTag(HtmlTextWriterTag.Td)
_txtUserID.RenderControl(output)
output.RenderEndTag()
output.RenderBeginTag(HtmlTextWriterTag.Td)
_valUserID.RenderControl(output)
output.RenderEndTag()
output.RenderEndTag()
output.RenderBeginTag(HtmlTextWriterTag.Tr)
output.RenderBeginTag(HtmlTextWriterTag.Td)
_lblPassword.RenderControl(output)
output.RenderEndTag()
output.RenderBeginTag(HtmlTextWriterTag.Td)
_txtPassword.RenderControl(output)
output.RenderEndTag()
output.RenderBeginTag(HtmlTextWriterTag.Td)
_valPassword.RenderControl(output)
output.RenderEndTag()
output.RenderEndTag()
output.RenderBeginTag(HtmlTextWriterTag.Tr)
output.AddAttribute(HtmlTextWriterAttribute.Colspan, "2")
output.AddAttribute(HtmlTextWriterAttribute.Align, "right")
output.RenderBeginTag(HtmlTextWriterTag.Td)
_button.RenderControl(output)
output.RenderEndTag()
output.RenderBeginTag(HtmlTextWriterTag.Td)
output.Write(" ")
output.RenderEndTag() 'TD
output.RenderEndTag() 'TR
output.RenderEndTag() 'Table
End Sub
#End Region 'Overridden Controls
End Class
What am I missing?
Thanks,
Owen