473,395 Members | 1,502 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,395 software developers and data experts.

Templated Controls FindControl() error

Before I was using LoadControl and a slew of User Controls to achive the
same effect, but I realised a custom TemplatedControl was the better way of
doing it.

Anyway, this is the templated control's markup:

<ams:Comments id="amsComments" runat="server">
<Header>
<div id="CommmentList">
<h3 class="box">Article Comments</h3>
</Header>
<CommentTemplate>
<div class="Comment box">
<p class="ByLine"><ams:Author id="amsCommentAuthor" runat="server" />
posted this on <asp:Literal ID="amsCommentDate" Runat="server" /></p>
<asp:Literal ID="amsCommentContent" Runat="server" />
</div>
</CommentTemplate>
<Message>
<div class="box">
<p><asp:Literal id="amsMessage" runat="server" /></p>
</div>
</Message>
<Footer>
</div>
</Footer>
</ams:Comments>

I get the CommentTemplate ITemplate to .Instatiate() in a newly created
PlaceHolder then use that PlaceHolder's .FindControl() method to locate the
"amsCommentAuthor" and "amsCommentDate" controls and set their properties.

....but when there are more than two comments to render I get this Exception
once the first has been rendered:

Multiple controls with the same ID 'amsCommentAuthor' were found.
FindControl requires that controls have unique IDs.

but this doesn't seem right, since I was calling it from the PlaceHolder, so
it must have its own unique control ID namespace, even after explicitly
setting the PlaceHolder's .ID property.

Here's the C# causing the problem:
for(int i=0; i<cnt; i++) {

PlaceHolder phComment = new PlaceHolder();
phComment.ID = "comment_" + i.ToString();

_comment.InstantiateIn( phComment );

this.Controls.Add( phComment );

Author amsCommentAuthor = (Author)phComment.FindControl(
"amsCommentAuthor" );

amsCommentAuthor.amsAuthorHref = UrlHandler.GenerateLink(
"/AMS:ContactUser", _comments[i].User.Username );
amsCommentAuthor.amsAuthorName = _comments[i].User.Username;

Literal amsDatePosted = (Literal)phComment.FindControl("amsCommentDate");
amsDatePosted.Text = _comments[i].DateCreated.ToString();

Literal amsContent = (Literal)phComment.FindControl("amsCommentContent" );
amsContent.Text = _comments[i].Content;

}

Any ideas?

Many thanks
Jul 15 '06 #1
0 1244

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

Similar topics

2
by: | last post by:
Hello All, I am having a lot of difficulty trying to bind a templated column, that is programmatically created for a datagrid, to a datasource column. I have a datasource containing 2 columns,...
0
by: AC | last post by:
I've created a user control (ASCX) that contains two buttons. This control is programatically placed into a datagrid via the LoadTemplate method and the TemplateColumn object. What I'd like to do...
0
by: Adrijan Josic | last post by:
Ok I have made a templated user control using the sample in help that is used like this: <General:WebPage id="WebPage1" runat="server"> <Header> header </Header> <Left> <asp:Button
2
by: Earl Teigrob | last post by:
I have created a simple custom control that uses a table to create space around its contents. The code in the aspx page is show below. My problem is that the controls within the template can not be...
2
by: sck10 | last post by:
Hello, I am looping through each control using the following to find a particular control (strFindCtl = "tbxCompetitor" & strForLoop1 & "Product"). For ctrRow = 1 To 3 strForLoop1 = "0" &...
4
by: Bass Pro | last post by:
Hi, I am creating textbox, radiobuttonlist and checkboxlist dynamically depending on data from a table. It is a questionnaire. I add the control on a Panel control during the 1st load_page event....
0
by: JohnyStyles | last post by:
I have a templated user control which looks like this: ----------------------------------------------------------------- <uc:MyUserControl runat=server> <TemplateProperty> </TemplateProperty>...
1
by: Andrew Clancy | last post by:
Hi, Myself and a colleague are attempting to mimic the custom template functionality of the ASP.Net 2 Login control. Essentially, we would like to have the ability within our...
4
by: tshad | last post by:
Is there a way for a User Control to access an object (such as label or textbox) on the .aspx page that calls it? For example: x.aspx ************************************** .... Sub...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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,...
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.