ARTICLE

Working with PasswordBox in Silverlight using VB.NET

Posted by Alok Pandey Articles | Silverlight using VB.NET September 16, 2011
Here, we will learn how to use of PasswordBox in silverlight.
 
Reader Level:

Introduction: PasswordBox is used for password entry. Generally we use it, when we want the typed text will not display in readable form.

For working with it, we take a Silverlight control. Then we take two TextBlock, one TextBox, one PasswordBox and one Button by dragging it from ToolBox or by writing the following XAML code in editor

<Grid x:Name="LayoutRoot" Background="White">
        <PasswordBox Height="23" HorizontalAlignment="Left" Margin="152,87,0,0" Name="passwordBox1" VerticalAlignment="Top" Width="120" />                <TextBox Height="23" HorizontalAlignment="Left" Margin="152,41,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" />                                <TextBlock Height="23" HorizontalAlignment="Left" Margin="81,48,0,0" Name="textBlock1" Text="User Name" VerticalAlignment="Top" />                <TextBlock Height="23" HorizontalAlignment="Left" Margin="81,91,0,0" Name="textBlock2" Text="Password" VerticalAlignment="Top" />                <Button Content="Ok" Height="34" HorizontalAlignment="Left" Margin="166,150,0,0" Name="button1" VerticalAlignment="Top" Width="93" Click="button1_Click" />
</
Grid>

We write the following code on Button Click event

  Private Sub button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
            If textBox1.Text = "user" Then
            If passwordBox1.Password = "password" Then
                MessageBox.Show("Login Succes")
            Else
                MessageBox.Show("Password is not Correct")
            End If
            Else
                MessageBox.Show("Invalid User Name or Password")
            End If
            End
Sub

Now, we run our application. The output will be as like below figure

 passwordbox

Here user is User Name and password is Password. When we do right entry and Click ok button, then Login Success message box is appeared as like below figure

 passwordbox

If we do wrong entry for user name or password, then message box is appeared with message Password is not Correct or Invalid User Name or Password as like below figure

 

 passwordbox

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Diagram
Become a Sponsor