473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Tough Question: Accessing controls inside inline template in a user control, in a repeater

I have the following ASP.NET 2.0 code (simplified here for ease):

<asp:Repeater id="SearchResultsRepeater" runat="server">
<ItemTemplate>
<uc:SearchResult ID="SearchResult"
ResultObject="<%#Container.DataItem%>" runat="server">
<ButtonsTemplate>
<uc:ViewButton ID="ViewButton"
ListingReference='<%#Eval("ListingReference")%>' runat="server" />
</ButtonsTemplate>
</uc:SearchResult>
</ItemTemplate>
</asp:Repeater>

This works fine except for the databinding on user control "ViewButton"
property ListingReference. Does anyone know how to get the databinding to
work in this example?

For reference moving <uc:ViewButtonoutside the inline template will work
with no problem, but is not what I want:

<asp:Repeater id="SearchResultsRepeater" runat="server">
<ItemTemplate>
<uc:SearchResult ID="SearchResult"
ResultObject="<%#Container.DataItem%>" runat="server" />
<ButtonsTemplate>

</ButtonsTemplate>
</uc:SearchResult>
<uc:ViewButton ID="ViewButton"
ListingReference='<%#Eval("ListingReference")%>' runat="server" />
</ItemTemplate>
</asp:Repeater>

I have also tried accessing <uc:ViewButtonprogrammatically but I don't
know where to find the control:

Protected Sub SearchResultsRepeater_ItemDataBound(ByVal sender As
Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
SearchResultsRepeater.ItemDataBound
Dim result As SearchResultObject = CType(e.Item.DataItem,
SearchResultObject)
If result IsNot Nothing Then
Dim resultUserControl As SearchResult =
CType(e.Item.FindControl("SearchResult"), SearchResult)
' FOR EXAMPLE THIS WILL NOT WORK:
' Dim viewButton As ViewButton =
CType(resultUserControl.FindControl("ViewButton"), ViewButton)
' viewButton.ListingReference = result.ListingReference
End If
End Sub

Does anyone know how I find the control in this example?

Thanks!
Dec 20 '06 #1
1 2075
After using a hack that used CSS to place the buttons using positioning, I
decided to revisit this and come up with a proper ASP.NET solution. My user
control "Search Result" contains the following code:

Protected _buttonsTemplate As ITemplate = Nothing

<PersistenceMode(PersistenceMode.InnerProperty),
TemplateContainer(GetType(TemplateControl))_
Public Property ButtonsTemplate() As ITemplate
Get
Return _buttonsTemplate
End Get
Set(ByVal value As ITemplate)
_buttonsTemplate = value
End Set
End Property

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If _buttonsTemplate IsNot Nothing Then
_buttonsTemplate.InstantiateIn(ButtonsPlaceHolder)
End If
End Sub

I added an overrided CreateChildControls() routine and moved the code from
the Page_Load event:

Protected Overrides Sub CreateChildControls()
MyBase.CreateChildControls()
If _buttonsTemplate IsNot Nothing Then
_buttonsTemplate.InstantiateIn(ButtonsPlaceHolder)
End If
End Sub

I can now use FindControl to access any controls I place in the
<ButtonsTemplateinline template (see below)
"Dave" <no****@spam3mail.comwrote in message
news:fl*********************@fe1.news.blueyonder.c o.uk...
>I have the following ASP.NET 2.0 code (simplified here for ease):

<asp:Repeater id="SearchResultsRepeater" runat="server">
<ItemTemplate>
<uc:SearchResult ID="SearchResult"
ResultObject="<%#Container.DataItem%>" runat="server">
<ButtonsTemplate>
<uc:ViewButton ID="ViewButton"
ListingReference='<%#Eval("ListingReference")%>' runat="server" />
</ButtonsTemplate>
</uc:SearchResult>
</ItemTemplate>
</asp:Repeater>

This works fine except for the databinding on user control "ViewButton"
property ListingReference. Does anyone know how to get the databinding to
work in this example?

For reference moving <uc:ViewButtonoutside the inline template will work
with no problem, but is not what I want:

<asp:Repeater id="SearchResultsRepeater" runat="server">
<ItemTemplate>
<uc:SearchResult ID="SearchResult"
ResultObject="<%#Container.DataItem%>" runat="server" />
<ButtonsTemplate>

</ButtonsTemplate>
</uc:SearchResult>
<uc:ViewButton ID="ViewButton"
ListingReference='<%#Eval("ListingReference")%>' runat="server" />
</ItemTemplate>
</asp:Repeater>

I have also tried accessing <uc:ViewButtonprogrammatically but I don't
know where to find the control:

Protected Sub SearchResultsRepeater_ItemDataBound(ByVal sender As
Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs)
Handles SearchResultsRepeater.ItemDataBound
Dim result As SearchResultObject = CType(e.Item.DataItem,
SearchResultObject)
If result IsNot Nothing Then
Dim resultUserControl As SearchResult =
CType(e.Item.FindControl("SearchResult"), SearchResult)
' FOR EXAMPLE THIS WILL NOT WORK:
' Dim viewButton As ViewButton =
CType(resultUserControl.FindControl("ViewButton"), ViewButton)
' viewButton.ListingReference = result.ListingReference
End If
End Sub

Does anyone know how I find the control in this example?

Thanks!

Dec 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: buran | last post by:
Dear ASP.NET Programmers, I have a web user control (a search menu) which has 2 validation controls (one for input and another for the search criterion). I am including this search user control...
3
by: Craig G | last post by:
i have a user control which is basically a datagrid, which has add/edit/delete buttons on the grid is there anyway of accessing the actual datagrid from the form itself? basically i want to...
6
by: arvee | last post by:
Is there a way to access controls (and their properties) in a user control? The Web Form Designer marks controls as 'Protected' which makes them inaccessable from the host form. If I mark them as...
2
by: Brenden Bixler | last post by:
I have a user control, dropdown.ascx Inside dropdown.ascx, I have a dropdownlist control. From my page.aspx, I need to be able to access the dropdown's value. By setting it to auto-post...
1
by: Giorgio | last post by:
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes and I also would like to know how to access functions that are on aweb user control...
6
by: evandelagrammaticas | last post by:
Hi all. I have spent the better part of a day scouring the newsgroups and I am sure that I must have come across the solution a number of times - but I am still a real newbie at asp.net so please...
2
by: | last post by:
I want to use codebehind to pass property values to a control that I've embedded INSIDE of a user control. In other words, let's say I have the following: MyPage.aspx ....with the following...
0
by: erkbiz | last post by:
Hello, this is my first post, I hope this is the right forum to ask my question. I am dynamically loading a user control multiple times. I have a gridview and have inserted empty rows. Into these...
0
by: Jeff | last post by:
Hi, I've created a template user control and followed the example on the MSDN (the message template with fruit as the example). However, my template needs to be an input control, similar to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.