Masked password textbox in LightSwitch


In this article you will see how to create a masked word textbox. A masked control is used to save time and reduce the complaints and errors. They enhance the function of the textbox control, which can validate the input. By default the property masked is set to none. A word textbox is used for authorization of an any application. It is very useful to provide security for any application.

Step by step solution

Step 1 : Open Visual Studio LightSwitch then create a new table.

1st.png

Step 2 : Create a table called customer like below.

2nd.png

Step 3 : Right click on screens->Add screen.

3rd.png

Step 4 : Select new data screen->Select screen data (customer)->Ok.

4th.png

Step 5 : Expand word->Select textbox and custom control.

5th.png

Step 6 : Go to word properties->Click change.

6th.png

Step 7 : Now select word control->Ok.

7th.png

Step 8 : Click write code->Select CreateNewCustomer_InitializeDataWorkSpace->Write the following code.

8th.png

Code :

using
System;
using System.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Framework.Client;
using Microsoft.LightSwitch.Presentation;
using Microsoft.LightSwitch.Presentation.Extensions;
namespace LightSwitchApplication
{
    public partial class CreateNewCustomer
    {
        partial void CreateNewCustomer_InitializeDataWorkspace(List<IDataService> saveChangesTo)
        {
            // Write your code here.
            this.CustomerProperty = new Customer();
             this.FindControl("word").ControlAvailable += pwdAvailable;
        }
        private void pwdAvailable(object sender, ControlAvailableEventArgs e)
        {
            ((System.Windows.Controls.Control)e.Control).LostFocus += wordLostFocus;
        }
        private void wordLostFocus(object sender, System.Windows.RoutedEventArgs e)
        {
             this.CustomerProperty.word = ((System.Windows.Controls.wordBox)sender).word;
        }
        partial void CreateNewCustomer_Saved()
        {
            // Write your code here.
            this.Close(false);
            Application.Current.ShowDefaultScreen(this.CustomerProperty);
        }
    }
}

Step 9 : Run application (Press F5) then enter username and word for create new customer.

9th.png

Conclusion

So word control is very useful for security purpose. The masked word control is used for checks the validations.


Similar Articles