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
t
extbox
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.
Step 2 : Create a table called customer like below.
Step 3 : Right click on screens->Add
screen.
Step 4 : Select new data screen->Select
screen data (customer)->Ok.
Step 5 : Expand word->Select textbox
and custom control.
Step 6 : Go to word
properties->Click change.
Step 7 : Now select word
control->Ok.
Step 8 : Click write code->Select
CreateNewCustomer_InitializeDataWorkSpace->Write the following code.
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.
Conclusion
So word control is very useful for security
purpose. The masked word control is used for checks the validations.