Imports System Imports System.Web Imports System.Web.UI Imports System.Web.UI.WebControls Namespace myControls Public Class LoginEvent Inherits Control Implements INamingContainer Sub CheckPassword( s As Object, e As EventArgs ) Dim strUsername, strPassword As String Dim lblLabel As Label strUsername = CTYPE( Controls( 2 ), TextBox ).Text strPassword = CTYPE( Controls( 5 ), TextBox ).Text lblLabel = CTYPE( Controls( 9 ), Label ) If strUsername = "joe" and strPassword = "secret" Then lblLabel.Text = "Welcome Joe!" Else lblLabel.Text = "Invalid Password!" End If End Sub Protected Overrides Sub CreateChildControls() Me.Controls.Add( New LiteralControl( "
" ) ) ' Add Username Me.Controls.Add( New LiteralControl( "Username: " ) ) Me.Controls.Add( New TextBox ) Me.Controls.Add( New LiteralControl( "

" ) ) ' Add Password Dim txtPass As New TextBox Me.Controls.Add( New LiteralControl( "Password: " ) ) txtPass.TextMode = TextBoxMode.Password Me.Controls.Add( txtPass ) Me.Controls.Add( New LiteralControl( "

" ) ) ' Add Submit Button Dim btnButton As New Button btnButton.Text = "Login!" AddHandler btnButton.Click, AddressOf checkPassword Me.Controls.Add( btnButton ) Me.Controls.Add( New LiteralControl( "

" ) ) ' Add Label Control Dim lblLabel As New Label lblLabel.EnableViewState = False Me.Controls.Add( lblLabel ) End Sub End Class End Namespace