Using the TextBox's TextChanged event from inside a DataList

  • Thread starter Thread starter Nathan Sokalski
  • Start date Start date
N

Nathan Sokalski

I have a DataList that contains TextBoxes. I want to postback when the
TextChanged event occurs. I have the TextBox's AutoPostBack property set to
True, but it does not seem to be doing a postback. I would expect this to
bubble up to the DataList's ItemCommand event, but this does not seem to be
happening. I will note that the DataList is inside an UpdatePanel, but it
should still do the postback. Any ideas why this is not working? Thanks.
 
I have found how to get the TextChanged event to fire, using the following
code:

Private Sub datCart_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles datCart.ItemCreated
AddHandler CType(e.Item.FindControl("txtQuantity"), TextBox).TextChanged,
AddressOf Me.TextChanged
End Sub

However, in the eventhandler I need to know which item the TextBox that
fired the event came from, otherwise making the TextBox part of the DataList
is pointless. I need to know either the index or the associated DataKey.
Events such as ItemCommand allow you to access the ItemIndex using the
second argument of the event handler. I have figured out how to get access
to the DataListItem and DataList it came from by using properties of the
sender argument, but even the DataListItem does not supply me with the
index. The only solution I can come up with is to add a Hidden field to the
Template that holds the value I need, but I would prefer not to do this. If
anybody knows of a more efficient method, please let me know. Thanks.
 
Back
Top