Solved

Accessing TextBox from FooterTemplate

Posted on 2006-06-30
8
424 Views
Last Modified: 2008-02-01
I have scenario where I need to be able to find and obtains values from a Server Control TextBox in a FooterTemplate and not ItemTemplate (which is the norm for everyone else).   I need to do this in postback meaning I need to find the control in some sort of collection and use the values.   But the problem is I can't seem to find the right collection to search through.   Like for Items in the ItemTemplate collection it's easy to find what I'm looking for.  I just do a for loop through the collection and then find the control i'm looking for.    But I don't know how to do this for an item/object in the FooterTemplate.    Anyone?   Here's the declarative code for the repeater I'm using with the object in the FooterTemplate:

<asp:Repeater ID="healthPlanGroupRepeater" Runat="server">
<HeaderTemplate>
            <table class="PBMDetailHealthPlanGroupSection" cellpadding="0" cellspacing"0" border="0" width="435">
                        <tr>                                            
                                    <td width="150">Group Name</td>
                                    <td width="10"><img height="1" src="Images/spacer.gif" width="10"></td>
                                    <td width="150">Group Id</td>
                                    <td width="10"><img height="1" src="Images/spacer.gif" width="10"></td>
                                    <td width="105">Cancel Date</td>
                                    <td width="10"><img height="1" src="Images/spacer.gif" width="10"></td>
                        </tr>
</HeaderTemplate>
<ItemTemplate>
                        <tr valign="top">
                                    <td><asp:TextBox Runat="server" id="groupNameTextBox"></asp:TextBox></td>
                                    <td><input type="hidden" runat="server" id="hiddenGroupUniqueIdentifier"/></td>
                                    <td><asp:TextBox Runat="server" id="groupIdTextBox"></asp:TextBox></td>
                                    <td></td>
                                    <td><picCalendar:Calendar ID="picGroupCancelDateTextBox" Runat="server" /></td>
                                    <td></td>
                        </tr>
</ItemTemplate>
<FooterTemplate>                                                        
                        <tr class="PBMDetailNewHealthPlanGroupSection">
                                    <td class="PBMDetailHealthPlanGroupHeader">Add Group</td>
                                    <td class="PBMDetailHealthPlanGroupSectionDivider"></td>
                                    <td><asp:TextBox ID="addHealthPlanGroupNameTextBox" Runat="server" /></td>
                                    <td><asp:TextBox ID="addHealthPlanGroupIdTextBox" Runat="server" /></td>
                                    <td></td>
                                    <td><picCalendar:Calendar ID="picAddHealthPlanGroupCancelDate" Runat="server" /></td>
                        </tr>                                          
            </table>                        
</FooterTemplate>      
</asp:Repeater>

So I want to be able to access the 'addHealthPlanGroupNameTextBox' TextBox in PostBack.  Thanks for your help!
0
Comment
Question by:calvinklein1
  • 5
  • 3
8 Comments
 
LVL 4

Expert Comment

by:Kittrick
ID: 17019977
Hi there,
According to:
http://msdn.microsoft.com/library/?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolsrepeaterclasstopic.asp

"A Repeater binds its ItemTemplate and AlternatingItemTemplate to a data model declared and referenced by its DataSource property. The HeaderTemplate, FooterTemplate, and SeparatorTemplate are not data-bound."

This is going to make it tough to grab the data you want. I don't know if it's possible to put a second repeater on a page, but if it's possible, you could try that.

Kittrick

0
 
LVL 4

Expert Comment

by:Kittrick
ID: 17020033
You could also try in your footertemplate to grab the value stored in the itemtemplate of the box you want then hide the box in the <itemtemplate>.

You have:
<asp:TextBox ID="addHealthPlanGroupNameTextBox" Runat="server" />

in your footer template...but you could try:

<asp:TextBox ID="addHealthPlanGroupNameTextBox" Runat="server" text='<%# DataBinder.Eval(Container.DataItem, "the field to grab from itemtemplate")%>' />

then in the textbox you are grabbing the data from in the <itemtemplate>, you can hide by:

<asp:TextBox ID="addHealthPlanGroupNameTextBox" Runat="server" visible=false/>


so put together, it would look like this:

<repeater>
<itemtemplate>
<asp:TextBox ID="addHealthPlanGroupNameTextBox" Runat="server" visible=false/>

</itemtemplate>

<footertemplate>

<asp:TextBox ID="addHealthPlanGroupNameTextBox1" Runat="server" text='<%# DataBinder.Eval(Container.DataItem, "the field to
</footertemplate>
</repeater>

Hope that helps!
Kittrick
0
 

Author Comment

by:calvinklein1
ID: 17020072
It's an object that is filled in by the user not obtained from data collection.   This is a new row, data entry.  

This repeater is inside of another repeater so that does work.  I just didn't include all the code because it wasn't neccessary for this example.  

But I also saw what Microsoft has documented on this subject, but I have also read and heard people retrieving objects from the FooterTemplate or HeaderTemplate before.   I'm just not sure how they do it.   I thought by doing CType(repeaterItem.FindControl("healthPlanNameTextBox"), TextBox).Text  would give me the value of the TextBox but it doesn't appear to be working.   (That's yucky VB code by the way).    I think the reason why it's not working is because it's only looking in the ItemCollection rather than all the child controls within the Repeater control....
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 4

Expert Comment

by:Kittrick
ID: 17020077
Sorry for posting again, but my example got cut off when I posted...

<repeater>
<itemtemplate>
<asp:TextBox ID="addHealthPlanGroupNameTextBox" Runat="server" visible=false/>

</itemtemplate>

<footertemplate>

<asp:TextBox ID="addHealthPlanGroupNameTextBox1" Runat="server" text='<%# DataBinder.Eval(Container.DataItem, "addHealthPlanGroupNameTextBox")%>'/>
</footertemplate>
</repeater>
0
 
LVL 4

Expert Comment

by:Kittrick
ID: 17020129
samtran0331 sorta solved what you are looking for at:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21502128.html

but the complete solution wasn't posted:(  but here's his code that iterates through child controls:


Dim i As Integer
        'outer repeater
        For i = 0 To Repeater1.Items.Count - 1
            Dim innerRepeater As Repeater = New Repeater
            innerRepeater = CType(Repeater1.Items(i).FindControl("childRepeater"), Repeater)
            Dim j As Integer
            For j = 0 To innerRepeater.Items.Count - 1
                'this is the inner loop?

            Next
        Next

0
 
LVL 4

Accepted Solution

by:
Kittrick earned 500 total points
ID: 17020172
rafd123 created the following code at:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21025473.html

that will list all the controls on your page....I imagine you could go from there when trying to reference the one you are looking to have the user input into...

Private Sub ListControls(ByRef control As Control)
          'List each of the control's child controls
          For Each child As Control In control.Controls
               Trace.Warn("Unique ID :", child.UniqueID)
               'Recusively list all of the child's children
               ListControls(child)
          Next
     End Sub
0
 

Author Comment

by:calvinklein1
ID: 17020177
Found it.  I wasn't trying to find a repeater inside of another repeater.  I was trying to find an object within the FooterTemplate.
But I was concentrating too much on the Repeater Items rather than the Child Controls.

So I did this:

For i As Integer = 0 To healthPlanRepeater.Controls.Count - 1
            Dim addHealthPlanNameTextBox As TextBox = DirectCast(healthPlanRepeater.Controls.Item(i).FindControl("addHealthPlanNameTextBox"), TextBox)
            If Not (addHealthPlanNameTextBox Is Nothing) Then
                        If addHealthPlanNameTextBox.Text <> String.Empty Then
                                    Dim DoSomething As String = addHealthPlanNameTextBox.Text
                        End If
            End If
Next

Thanks for your help on this though.  i'll give you the points.
0
 

Author Comment

by:calvinklein1
ID: 17020183
ooo you got to it before I could post it.  hahaha. nice.  thanks again!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question