div with dynamic ID

M

Mark

Hi,

I have code like that:
<asp:Repeater ID="repClients" runat="server" >
<ItemTemplate>
<div runat="server" id="aaa" >
<div id="canFind" runat="server"></div>
<div id="clientHeader<%#Eval("ClientId")%>"
ClientId="bbb" UniqueID="ccc" runat="server"

In code begind I can find div named "canFind". In watch I do:
repClients.Items[0].FindControl("aaa").Controls[1].ID and I can see
"canFind"

But I can't find the div with dynamic id !! I check all Controls
collection, I try to find it by ClientId, UniqueID, but I doesn't
work, Why ?

How to find in c# div with dynamic Id ?

Thanks for help
 
G

Guest

Hi,

I have code like that:
<asp:Repeater ID="repClients" runat="server" >
     <ItemTemplate>
           <div runat="server" id="aaa" >
                <div id="canFind" runat="server"></div>
                <div id="clientHeader<%#Eval("ClientId")%>"
ClientId="bbb" UniqueID="ccc" runat="server"

In code begind I can find div named "canFind". In watch I do:
repClients.Items[0].FindControl("aaa").Controls[1].ID   and I can see
"canFind"

But I can't find the div with dynamic id !! I check all Controls
collection, I try to find it by ClientId, UniqueID, but I doesn't
work, Why ?

How to find in c# div with dynamic Id ?

Thanks for help

Hi Mark,

if you look at the source code of the generated page in runtime you
will see that this is not working - you have "runat=server" written in
the plain text next to the UniqueID="ccc". You can't assign and use ID
like that. I would suggest you to change that div to

<div id="canFind2" clientid="bbb" uniqueid="ccc" runat="server">

and use following code to get <div> from the code

foreach (Control c in repClients.Items[0].FindControl("aaa").Controls)
{
if (c.ID == "canFind2")
{
Response.Write(string.Format("Found: {0}", c.ID));
}
}

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top