Partager via


TextChanged, événement

Se produit lorsque l'utilisateur change le texte d'un contrôle TextBox.

public event System.EventHandler TextChanged

Notes

Lorsque l'utilisateur change le texte d'un contrôle TextBox, cet événement n'est pas déclenché immédiatement. Le formulaire doit contenir encore un contrôle Command pour permettre le renvoi des modifications au serveur. Les résultats sont alors renvoyés au serveur.

Exemple

L'exemple suivant montre comment utiliser l'événement TextChanged pour modifier les données liées à SelectionList.

[Visual Basic]

<Script language="vb" runat="server">

Public arr As New ArrayList()
Class Task
   Private _TaskName As String
   Private _Status As String
   
   
   Public Sub New(TaskName As String, Status As String)
      _TaskName = TaskName
      _Status = Status
   End Sub
   
   
   Public ReadOnly Property TaskName() As String
      Get
         Return _TaskName
      End Get
   End Property
   
   Public ReadOnly Property Status() As String
      Get
         Return _Status
      End Get
   End Property

End Class

Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

   If Not IsPostBack Then
   Label1.Text = "Enter the Task if it is not present in" + " List below"
   
   TextBox1.Alignment = System.Web.UI.MobileControls.Alignment.Center
   
   SelectionList1.SelectType = System.Web.UI.MobileControls.ListSelectType.MultiSelectListBox
   SelectionList1.Wrapping = System.Web.UI.MobileControls.Wrapping.NoWrap
   SelectionList1.DataValueField = "Status"
   SelectionList1.DataTextField = "TaskName"
   
   arr.Add(New Task("Verify transactions", "Done"))
   arr.Add(New Task("Check balance sheet", "Scheduled"))
   arr.Add(New Task("Call customer", "Done"))
   arr.Add(New Task("Pay checks", "Pending"))
   arr.Add(New Task("Send report", "Pending"))
   arr.Add(New Task("Attend meeting", "Scheduled"))
   
   ' Save array to use after postbacks.
   Session("array") = arr
   SelectionList1.DataSource = arr
   
   SelectionList1.DataBind()
   Label3.Text = "Taskes are arranged by their priority"

End If


End Sub


Sub TextChanged(sender As Object, e As EventArgs)

   arr = CType(Session("array"), ArrayList)
   arr.Add(New Task(TextBox1.Text, TextBox2.Text))
   
   SelectionList1.DataSource = arr
   SelectionList1.DataBind()
   
   Session("array") = arr
   
   'Expanding Selection list's view to see all items in the list.
   SelectionList1.Rows = SelectionList1.Items.Count

End Sub

<mobile:Form id="Form1" runat="server">
   <mobile:Label Id="Label1" runat="server" Alignment= "center" />   
   <mobile:Label Id="Label2" runat="server" Alignment= "center" 
      Text="Enter the Task name" />
   <mobile:TextBox runat="server" id="TextBox1" Alignment="center"
      OnTextChanged="TextChanged" />
   <mobile:Label Id="Label3" runat="server" Alignment= "center"
      Text="Enter the Task status" />
   <mobile:TextBox runat="server" id="TextBox2" Alignment= "center"/>
   <mobile:label id="Label4" runat=server Alignment= "center" />
   <mobile:SelectionList runat="server" id="SelectionList1"
      Alignment= "center"/>
   <mobile:Command runat="server" Text="Submit" Alignment="Center" />
</mobile:Form>

</Script>
<script runat=server language="c#">   
public ArrayList arr = new ArrayList();   
class Task
{
   private String _TaskName;
   private String _Status;

   public Task(String TaskName, String Status) 
   { 
      _TaskName = TaskName; 
      _Status   = Status;
   }   

   public String TaskName { get { return _TaskName; } }
   public String Status   { get { return _Status;   } }
}

void Page_Load(object sender, EventArgs e)
{
   if(!IsPostBack)
   {
      Label1.Text = "Enter the Task if it is not present in" +
         " List below"; 

      TextBox1.Alignment =
         System.Web.UI.MobileControls.Alignment.Center;

      SelectionList1.SelectType =
         System.Web.UI.MobileControls.ListSelectType.MultiSelectListBox;
      SelectionList1.Wrapping =
         System.Web.UI.MobileControls.Wrapping.NoWrap;
      SelectionList1.DataValueField = "Status";
      SelectionList1.DataTextField  = "TaskName";  

    arr.Add (new Task ("Verify transactions", "Done"));
    arr.Add (new Task ("Check balance sheet", "Scheduled"));
    arr.Add (new Task ("Call customer",       "Done"));
    arr.Add (new Task ("Pay checks",          "Pending"));
    arr.Add (new Task ("Send report",         "Pending"));
    arr.Add (new Task ("Attend meeting",      "Scheduled"));

    // Save array to use after postbacks.
    Session["array"]          = arr;
    SelectionList1.DataSource = arr;

    SelectionList1.DataBind();
    Label3.Text = "Tasks are arranged by their priority";
  }
}

void TextChanged(object sender, EventArgs e )
{
   arr = (ArrayList) Session["array"];   
   arr.Add(new Task (TextBox1.Text, TextBox2.Text));

   SelectionList1.DataSource = arr;
   SelectionList1.DataBind();

   Session["array"] = arr;

   //Expanding Selection list's view to see all items in the list.
   SelectionList1.Rows = SelectionList1.Items.Count;
}

</script>

<mobile:Form id="Form1" runat="server">
   <mobile:Label Id="Label1" runat="server" Alignment= "center" />   
   <mobile:Label Id="Label2" runat="server" Alignment= "center" 
      Text="Enter the Task name" />
   <mobile:TextBox runat="server" id="TextBox1" Alignment="center"
      OnTextChanged="TextChanged" />
   <mobile:Label Id="Label3" runat="server" Alignment= "center"
      Text="Enter the Task status" />
   <mobile:TextBox runat="server" id="TextBox2" Alignment= "center"/>
   <mobile:label id="Label4" runat=server Alignment= "center" />
   <mobile:SelectionList runat="server" id="SelectionList1"
      Alignment= "center"/>
   <mobile:Command runat="server" Text="Submit" Alignment="Center" />
</mobile:Form>

Voir aussi

OnTextChanged, méthode