HighTechTalks DotNet Forums  

Referencing Repeater Data in a User Control from a Page

ASP.net Building Controls microsoft.public.dotnet.framework.aspnet.buildingcontrols


Discuss Referencing Repeater Data in a User Control from a Page in the ASP.net Building Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
BigJohn
 
Posts: n/a

Default Referencing Repeater Data in a User Control from a Page - 02-07-2007 , 02:46 PM






I have successfully displayed text boxes in a repeater. The repeater is in a
User Control. The User Control is in a container which references a master
page.

I have another user control which contains text boxes. For this one, the
simple syntax of:
dim ctlWork as Textbox
ctlWork = ctype(Me.ctnInformation.FindControl("txtFName"), Textbox)
strWork = ctlWork.Text

In the case where I am having problems, the objects are laid out as follows:

Page Level:

<asp:Content ID="Main" ContentPlaceHolderID="ContentPlaceHolder1"
runat=server>
<table width="100%" border="1" bordercolor=black >
<tr>
<td width="100%">
<uc2:RegistrationE11 ID="RegistrationE11_1"
runat="server" />
</td>
</tr>
</table>
</asp:Content>


User Control:

<Table ID="tblE1Data" Border=0 Width="100%" runat=server >
<tr id="rowE1Update" runat=server>
<td>
<asp:TextBox ID="txtFName" runat=server MaxLength=100
Width=140px></asp:TextBox> (textbox is filled in codebehind)
<td>
<asp:Repeater ID="repUpdate" runat=server>
<HeaderTemplate >
<table width=100% border=0>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td>
<asp:textbox ID="RegIDE1" runat=server
Text=<%# Databinder.Eval(container.dataitem, "RegID") %>></asp:TextBox>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</td>
</tr>
</Table>


The intention is to have the user udpate the text boxes (there is more to
this project than what is shown of course), click the Update button on the
page, and apply the changes.

I tried Me.RegistrationE11_1.FindControl("RegIDE1") but the resulting type
is Nothing.

What is the syntax to look at all the textbox "RegIDE1" values from the
repeater on the user control in the main page?


Reply With Quote
  #2  
Old   
Steven Cheng[MSFT]
 
Posts: n/a

Default RE: Referencing Repeater Data in a User Control from a Page - 02-07-2007 , 10:20 PM






Hello John,

From your description, you're encountering some problem when try to access
a TextBox in the repeater control's template and the repeater is inside a
usercontrol which are used in the main page, correct?

Based on the code your provided, I think the problem here is that you
directly try locating the "Textbox"(which is inside repeater's
itemTemplate) through UserControl.FindControl method. This won't work since
you need to first get reference to the repeater control, and then locate
the certain RepeaterItem (since it will contains multiple RepeaterItem
after performing databinding). After that, you can call "FindControl"
method on the RepeaterItem instance to locate the TextBox. So the code
will look like below:

===================
Dim rpt As Repeater
rpt = RegistrationE11 .FindControl("repUpdate")

If Not rpt Is Nothing Then

For Each item As RepeaterItem In rpt.Items

Dim txt As TextBox = item.FindControl("RegIDE1")

txt.Text = txt.Text & "_updated"

Next

End If

End Sub
====================

Anyway, the basic rule is that if the control you want to locate is nested
in another control(which has implemented INamingContainer interface), you
need to find that control first and then call FindControl recursively to
locate its child controls.

BTW, for inspecting the control hierarchy in ASP.NET page, you can turn on
the output trace in the @Page directive. This is very help since it will
display the complete ASP.NET server control tree of the current page. You
can get the path you need to go through when try locating a control:

<%@ Page Language="C#" ............................. Trace="true"%>

Hope this helps.


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.