Solved

Accessing TextBox from FooterTemplate

Posted on 2006-06-30
8
420 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

17 Experts available now in Live!

Get 1:1 Help Now