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
 
Ad

Advertisements

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

Top