Richard77
Richard77

Reputation: 21641

How to capture a textchanged event when the textbox is inside a ListView?

I have a series of textbox in a listview which contain the hours and minutes for employees. I want values entered to be computed when any of the textboxes loses focus. I've tried this exemple from the MSDM. For button and LinkButton, I can use OnItemCommand, for DDl and listbox, I can use OnSelectedIndexChanged.

How about Textchanged for my texboxes? I don't see any event for them. From MSDN, the only method that resemble to that is TextBox.TextChanged Event. But it said on that page : "This API supports the .NET Framework infrastructure and is not intended to be used directly from your code."

Upvotes: 2

Views: 5680

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460158

The TextBoxes are in the ItemTemplate(or EditItemTemplate), aren't they? If they have AutoPostBack=true they'll post back as soon as the text changed and the focus lost. Just the same as outside of a ListView.

on aspx:

<ItemTemplate>
  <tr runat="server">
    <td>
      <asp:TextBox OnTextChanged="TextBox1_TextChanged" AutoPostBack="true"
            ID="Textbox1" runat="Server" Text="here is text"  />
    </td>
    <td>
  </tr>
</ItemTemplate>

in codebehind:

protected void TextBox1_TextChanged(object sender, EventArgs e)
{
   TextBox TextBox1 = (TextBox) sender;
}

Upvotes: 5

Related Questions