Solved

Accessing TextBox from FooterTemplate

Posted on 2006-06-30
8
422 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now