Using the TextBox's TextChanged event from inside a DataList

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.
 
N

Nathan Sokalski

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top