473,748 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="SearchResul tsRepeater" runat="server">
<ItemTemplate >
<uc:SearchResul t ID="SearchResul t"
ResultObject="< %#Container.Dat aItem%>" runat="server">
<ButtonsTemplat e>
<uc:ViewButto n ID="ViewButton "
ListingReferenc e='<%#Eval("Lis tingReference") %>' runat="server" />
</ButtonsTemplate >
</uc:SearchResult >
</ItemTemplate>
</asp:Repeater>

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

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

<asp:Repeater id="SearchResul tsRepeater" runat="server">
<ItemTemplate >
<uc:SearchResul t ID="SearchResul t"
ResultObject="< %#Container.Dat aItem%>" runat="server" />
<ButtonsTemplat e>

</ButtonsTemplate >
</uc:SearchResult >
<uc:ViewButto n ID="ViewButton "
ListingReferenc e='<%#Eval("Lis tingReference") %>' runat="server" />
</ItemTemplate>
</asp:Repeater>

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

Protected Sub SearchResultsRe peater_ItemData Bound(ByVal sender As
Object, ByVal e As System.Web.UI.W ebControls.Repe aterItemEventAr gs) Handles
SearchResultsRe peater.ItemData Bound
Dim result As SearchResultObj ect = CType(e.Item.Da taItem,
SearchResultObj ect)
If result IsNot Nothing Then
Dim resultUserContr ol As SearchResult =
CType(e.Item.Fi ndControl("Sear chResult"), SearchResult)
' FOR EXAMPLE THIS WILL NOT WORK:
' Dim viewButton As ViewButton =
CType(resultUse rControl.FindCo ntrol("ViewButt on"), ViewButton)
' viewButton.List ingReference = result.ListingR eference
End If
End Sub

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

Thanks!
Dec 20 '06 #1
1 2101
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 _buttonsTemplat e As ITemplate = Nothing

<PersistenceMod e(PersistenceMo de.InnerPropert y),
TemplateContain er(GetType(Temp lateControl))_
Public Property ButtonsTemplate () As ITemplate
Get
Return _buttonsTemplat e
End Get
Set(ByVal value As ITemplate)
_buttonsTemplat e = value
End Set
End Property

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
If _buttonsTemplat e IsNot Nothing Then
_buttonsTemplat e.InstantiateIn (ButtonsPlaceHo lder)
End If
End Sub

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

Protected Overrides Sub CreateChildCont rols()
MyBase.CreateCh ildControls()
If _buttonsTemplat e IsNot Nothing Then
_buttonsTemplat e.InstantiateIn (ButtonsPlaceHo lder)
End If
End Sub

I can now use FindControl to access any controls I place in the
<ButtonsTemplat einline template (see below)
"Dave" <no****@spam3ma il.comwrote in message
news:fl******** *************@f e1.news.blueyon der.co.uk...
>I have the following ASP.NET 2.0 code (simplified here for ease):

<asp:Repeater id="SearchResul tsRepeater" runat="server">
<ItemTemplate >
<uc:SearchResul t ID="SearchResul t"
ResultObject="< %#Container.Dat aItem%>" runat="server">
<ButtonsTemplat e>
<uc:ViewButto n ID="ViewButton "
ListingReferenc e='<%#Eval("Lis tingReference") %>' runat="server" />
</ButtonsTemplate >
</uc:SearchResult >
</ItemTemplate>
</asp:Repeater>

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

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

<asp:Repeater id="SearchResul tsRepeater" runat="server">
<ItemTemplate >
<uc:SearchResul t ID="SearchResul t"
ResultObject="< %#Container.Dat aItem%>" runat="server" />
<ButtonsTemplat e>

</ButtonsTemplate >
</uc:SearchResult >
<uc:ViewButto n ID="ViewButton "
ListingReferenc e='<%#Eval("Lis tingReference") %>' runat="server" />
</ItemTemplate>
</asp:Repeater>

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

Protected Sub SearchResultsRe peater_ItemData Bound(ByVal sender As
Object, ByVal e As System.Web.UI.W ebControls.Repe aterItemEventAr gs)
Handles SearchResultsRe peater.ItemData Bound
Dim result As SearchResultObj ect = CType(e.Item.Da taItem,
SearchResultObj ect)
If result IsNot Nothing Then
Dim resultUserContr ol As SearchResult =
CType(e.Item.Fi ndControl("Sear chResult"), SearchResult)
' FOR EXAMPLE THIS WILL NOT WORK:
' Dim viewButton As ViewButton =
CType(resultUse rControl.FindCo ntrol("ViewButt on"), ViewButton)
' viewButton.List ingReference = result.ListingR eference
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
3693
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 in ever page in my application. In pages with validation controls, both the validation controls in the web user control and the normal form page are both enabled and I would like to know how to seperate them? I want to the 2 validation controls to...
3
1644
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 set the add/edit/delete options visble/invisible on the datagrid depending on the users's role, but found that i cannot access the grid to do this. is the only way of setting it in the page load of the usercontrol itself?
6
2251
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 Public, I can access them, but the next time the controls are manipulated in the design mode, they are converted back to Protected. Is there an obvious/easy way around this? Thanks.
2
3508
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 back, I am able to grab this value using Request.Form. This worked well until I realized that I needed the initial value in some cases. How do I access this value from the page.aspx file?
1
1439
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 X from a web user control Y, is this possible? How can I do it?
6
4075
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 forgive me beforehand if I ask anything really simple or ridiculous. I am going to simplify my query... the structure of my example is ---> page1.aspx ------> page1.aspx.vb --->control1.ascx for the sake of simplicity this is what I am trying...
2
1560
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 control placed on it... MyUserControl.ascx .... and inside of MyUserControl.ascx, is an instance of .... MyCommercialUploadControl1
0
1246
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 empty rows I am dynamically loading a .ascx user control (it too being a gridview) multiple times each time it loads it renders different data. I want to be able to access the data in the different gridviews is this possible? This snippet is...
0
1124
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 login; in that the developer can specify a template or use the default layout. I've got it working however, if I create my template in the Page_Init, as in the example, when I do a post back the value of the control as entered by the user is lost....
0
8830
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9544
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9372
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8243
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4606
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.