Issues with OnTextChanged using <asp:Repeater

F

Fred Dag

As far as I can work out when using the OnTextChanged event I cannot get the
TextBox and Labels values when the event fires as they are populated by a
<asp:repeater and so don't have values.

If I try to give the repeater values by removing
if (!IsPostBack)

{}

from the

Page_Load() method then my method is not called by the OnTextChanged event.

There is probably a limitation with my understanding of the event model.

How should I be getting OnTextChanged events from a <asp:repeater component
and getting details about the values from the other controls of the
<ItemTemplate> line that caused the event to trigger?



Thanks in advance
 
T

Teemu Keiski

Hi,

if you have specific problems can you show the code?

Anyways, if you get TextChanged event to be raised, you can get to the
current repeater's item via sender (first argument in event handler method)
with code as follows:

RepeaterItem ritem =(RepeaterItem)((Control)sender).NamingContainer;

It would be the the parent item of the TextBox which raises this specific
TextChanged event. Then getting to other controls on the same item would be
just running FindControl againts the RepeaterItem

Label lbl=(Label)ritem.FindControl("Label1");

and so on
 
Joined
Jul 18, 2007
Messages
1
Reaction score
0
Perfect, Just what I was looking for, Thanks Teemu

I have multiple cascading repeaters and have textboxes at the bottom of a repeater to add new items to that repeater. What I was looking for when I found your solution was a way to check user input in one textbox and then basically autofill the other textboxes in the same row with a database call if a match existed. Easy enough with a button but I wanted to use the ontextchanged event of the first textbox. This is what I did....Just in case anyone else happens to be looking.

Thanks again Teemu,

Paul



HTML:
<td colspan="2">
 <asp:TextBox ID="NewGroupCode" runat="server" AutoPostBack="true" OnTextChanged= "OnNewGroupCodeChanged" Width="100px"></asp:TextBox>
</td>


Code:
    Protected Sub OnNewGroupCodeChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim Adapter As New DSOrderTableAdapters.tblCodesMasterTableAdapter
        If CInt(Adapter.CountCodeMFG(sender.text.ToString, ddlMake.Text)) > 0 Then
            Dim ritem As RepeaterItem = CType((CType(sender, Control)).NamingContainer, RepeaterItem)
            Dim NewGroupCodeDesc1 As TextBox = CType(ritem.FindControl("NewGroupCodeDesc1"), TextBox)
            Dim NewGroupCodePrice As TextBox = CType(ritem.FindControl("NewGroupCodePrice"), TextBox)
            Dim NewGroupCode As TextBox = CType(ritem.FindControl("NewGroupCode"), TextBox)

            Dim Many As DSOrder.tblCodesMasterDataTable
            Dim One As DSOrder.tblCodesMasterRow
            Many = Adapter.GetCodeByCodeMFG(sender.text.ToString, ddlMake.Text)

            For Each One In Many
                NewGroupCodeDesc1.Text = One.Description1
                NewGroupCodePrice.Text = One.Price
            Next
            NewGroupCode.Text = sender.text.ToString.ToUpper
        End If
    End Sub
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top