Articles → LIGHT SWITCH 2011 → Textchanged Event Of Textbox Control In Lightswitch 2011

Textchanged Event Of Textbox Control In Lightswitch 2011






Software Requirement




  1. Visual studio 2010 is installed on your machine.
  2. Visual Studio 2010 service pack 1 is installed on your machine.
  3. Microsoft Visual Studio Light switch 2011 is installed on your machine.

Prerequisite Knowledge




  1. How to create screens in lightswitch?
  2. How to add data items?
  3. What is ControlAvailable event?
  4. What is screen’s created event.

Create A New Screen




Picture showing the designer screen of the new data screen
Click to Enlarge


Add Data Items In Screen




Picture showing adding the Message and MessageCount data item on the screen
Click to Enlarge


Drag Data Items On The Screen




Picture showing the data items dragged and dropped on the designer screen
Click to Enlarge


Change Control Type Of Data Item




Picture showing converting the Message Count field to Label
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();
}


  1. In ControlAvailable event I am checking if the control is a textbox control.
  2. If yes cast control in a variable.
  3. Register TextChanged event.

Register Textchanged Event




void txt_TextChanged(object sender, TextChangedEventArgs e) {
  TextBox txtControl = (TextBox) sender;
  this.MessageCount = txtControl.Text.Length.ToString();
}



Output


Picture showing the output of Textchanged event of textbox control in lightswitch 2011
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, July 17, 2012

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250