Articles → LIGHT SWITCH 2011 → Textchanged Event Of Textbox Control In Lightswitch 2011
Textchanged Event Of Textbox Control In Lightswitch 2011
Software Requirement
- Visual studio 2010 is installed on your machine.
- Visual Studio 2010 service pack 1 is installed on your machine.
- Microsoft Visual Studio Light switch 2011 is installed on your machine.
Prerequisite Knowledge
- How to create screens in lightswitch?
- How to add data items?
- What is ControlAvailable event?
- What is screen’s created event.
Create A New Screen
Click to Enlarge
Add Data Items In Screen
Click to Enlarge
Drag Data Items On The Screen
Click to Enlarge
Change Control Type Of Data Item
Click to Enlarge
Controlavailable Event On Created Method
partial void TextChangeDemo_Created() {
this.FindControl("Message").ControlAvailable += new EventHandler < ControlAvailableEventArgs > (TextChangeDemo_ControlAvailable);
}
void TextChangeDemo_ControlAvailable(object sender, ControlAvailableEventArgs e) {
throw new NotImplementedException();
}
Register Textchanged Event
void TextChangeDemo_ControlAvailable(object sender, ControlAvailableEventArgs e) {
if (e.Control is TextBox) {
TextBox txt = (TextBox) e.Control;
txt.TextChanged += new TextChangedEventHandler(txt_TextChanged);
}
}
void txt_TextChanged(object sender, TextChangedEventArgs e) {
throw new NotImplementedException();
}
- In ControlAvailable event I am checking if the control is a textbox control.
- If yes cast control in a variable.
- Register TextChanged event.
Register Textchanged Event
void txt_TextChanged(object sender, TextChangedEventArgs e) {
TextBox txtControl = (TextBox) sender;
this.MessageCount = txtControl.Text.Length.ToString();
}
Output
Click to Enlarge