Thanks Steven. The lifecycle explanation is helpful, though I still haven't
figured out a solution for my particular application. For others that might
stumble across this thread, this page is also helpful:
http://msdn2.microsoft.com/en-us/library/ms178472.aspx
I will explain bit more about what I'm tryiing to do and show some code. I
have a usercontrol called "ImageRepeater" that is intended to display a
series of photos. The photos are relationally linked to a parent article,
and I can query for a collection of photographs. The SqlDataSource that is
attached to ImageRepeater is intended to tell the repeater what ContentIDs
to load in each iteration of the repeater.
Within the "ImageRepeater" control, I'm attempting to bind a bunch of
"ImageBox" controls, another control I've made. Each ImageBox manages its
own data access.
The failure I'm having is that while the individual ImageBoxes in the
repeater will render OK if they're supplied a dummy value, they do not
dynamically evaluate the ID that I'm trying to supply through an Eval in the
declarative code.
I didn't completely follow your suggestion -- this stuff is not my forte --
but from reading the page above and reading your message, it would seem that
if I can move some aspects of this operation from declarative markup to
code, it may fix the problem. I can attach a method to ItemDataBound and
other events in the repeater's lifecycle, but I'm not sure that's the major
issue. The nested ImageControls controls WILL render properly if a hardcoded
ContentID is supplied to their parent; the nested controls are working
properly in the repeater once they know what it is they're supposed to be
rendering. What I need is some way to programmatically "grab" what should be
the active ContentID given the repeater's current position. Alternately,
maybe we could consider some sort of solution in which I first grabbed an
array of ContentIDs corresponding to the photos I wanted to display in the
imagerepeater, and subsequently, as each iteration of the repeater happened,
it would fire a "where am I now" function that would grab the right
ContentID and programmatically populate the variable being fed to the
individual ImageBox controls. I'm not exactly sure how to do that, but I
haven't played with this yet. I'm wondering if its the best approach.
I'm attaching my declarative markup below. If there's an optimum way (or any
way) to make this happen, please let me know.
This is the declarative code for ImageRepeater:
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="Uwn_ImageRepeater.ascx.cs"
Inherits="App_UserControls_Presentational_Show_Ima geRelated_Uwn_ImageRepeater"
%>
<%@ Register Src="Uwn_ImageBox.ascx" TagName="Uwn_ImageBox" TagPrefix="uc1"
%>
<asp:SqlDataSource ID="NewsReleasesWithIcons" runat="server"
ConnectionString="<%$ ConnectionStrings:XXXX %>"
SelectCommand="SELECT TOP (5)
Contentitems_RelatedContentitems.Con_ConRelID,
Contentitems_RelatedContentitems.Con_ConRelTo, ...)">
</asp:SqlDataSource>
<asp:Repeater ID="Repeater1" runat="server"
DataSourceID="NewsReleasesWithIcons" >
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<uc1:Uwn_ImageBox ID="Uwn_ImageBox1"
runat="server" ImageWidth="200" ContentID='<%# Eval("Con_ConRelTo") %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:51**************@TK2MSFTNGHUB02.phx.gbl...
Hello KF,
Regarding on the problem you meet here, I think it is due to the control's
initializing and databinding sequence in ASP.NET page. When you have a
usercontrol defined in Repeater's ItemTemplate, the ASP.NE page will
intializing the usercontrol in the following sequence:
i) first, when repeater is bound to a datasource, each repeaterItem is
created(any sub controls in it will also be created)
ii) after each repeater item and sub controls be created,it will perform
databinding on each repeaterItem.
Therefore, if you want to initialize the usercontrol(and its sub content)
in the sequence you want (1) .. 2) ..3) ..4) ...), you may need to
consider
the following means:
** still using DataBinding to intiailze the public property on your
Usercontrol, and this databinding will occur after your usercontrol and
its
content controls be created and initializing. So if you have other
initiailzing code(such as populating a databound list control from
database...), you need to put it in other event time (as below)
** move the code that populate other controls in Usercontrol(from
database)
depend on the public property (be initiailzed through databinding in the
previous step) to other place. One proper event is the Repeater control's
ItemDataBound event, this event fires after each RepeaterItem has
performed
databinding. And in that event you can try get your Usercontrol's
instance
and call some public methods on your usercontro. e.g.
====================
protected void Repeater1_ItemDataBound(object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
uc_WebUserControl wuc = e.Item.FindControl("WebUserControl1")
as uc_WebUserControl;
//suppose you have expose a public function to do the further databinding
(from database) in your usercontrol
wuc.FillDataGrid();
}
}
=====================
#note that in ItemDataBound, we should not create new controls here, but
can adjust some control's states or peform some databinding operations
here
because this event is fired only when the repeater is being databound to
datasource(not in each page request).
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.