Solved

Accessing TextBox from FooterTemplate

Posted on 2006-06-30
8
430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

627 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