473,509 Members | 2,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Asp controls Id generation inside repeater

1 New Member
I define some controls inside repeater itemtemplate, the problem is with the Id that are generated automatically.

Expand|Select|Wrap|Line Numbers
  1. <asp:Repeater ID="rptThreads" runat="server"            
  2.            onitemcreated="rptThreads_ItemCreated"> 
  3.         <HeaderTemplate> 
  4.            <table  cellpadding="0px" cellspacing="0">              
  5.         </HeaderTemplate> 
  6.  
  7.         <ItemTemplate>         
  8.            <tr style="height:50px">             
  9.              <td> 
  10.                 <asp:PlaceHolder ID="plcItemTitle" runat="server">                
  11.                   <asp:Panel id="titleContainer" runat="server" style="position:absolute;"> 
  12.                      <asp:HyperLink  ID="lnkTitle" runat="server" style="float:left;padding-right:10px;" Text='<%# Container.DataItem%>'/>             
  13.                      <asp:Panel id="pnlEditButtons" runat="server" Visible="false" style="vertical-align:middle;z-index:100;display:none;float:left;" >                                                                                         
  14.                        <asp:ImageButton ID="imgbtn1" runat="server"  ImageUrl="~/Images/misc/edit.png"   />                    
  15.                        <asp:ImageButton ID="imgbtn2" runat="server" ImageUrl="~/Images/misc/Rename.png" />                  
  16.                      </asp:Panel>                            
  17.                   </asp:Panel>                
  18.                </asp:PlaceHolder> 
  19.             </td>               
  20.            </tr> 
  21.         </ItemTemplate>         
  22.         <FooterTemplate> 
  23.            </table>  
  24.         </FooterTemplate>  
  25.     </asp:Repeater> 
  26.  
Now I will try to describe the problem:

code-behind:

Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e) 
  2.     { 
  3.        int [] array = {1,2,3,4,5}; 
  4.        rptThreads.DataSource = array; 
  5.        rptThreads.DataBind();      
  6.     } 
  7.  
  8.     protected void rptThreads_ItemCreated(object sender, RepeaterItemEventArgs e) 
  9.     { 
  10.         if (e.Item.ItemType == ListItemType.Item || 
  11.                e.Item.ItemType == ListItemType.AlternatingItem) 
  12.         { 
  13.  
  14.             Panel editButtonsPanel = e.Item.FindControl("pnlEditButtons") as Panel; 
  15.             editButtonsPanel.Visible = true; 
  16.             Panel containerPanel = e.Item.FindControl("titleContainer") as Panel; 
  17.  
  18.            //Point of Interest!!!! 
  19.            containerPanel.Attributes.Add("onmouseover", "ShowEditButtons('" + editButtonsPanel.ClientID + "');"); 
  20.          } 
  21.  
  22.  
  23.     } 
If I run the page as is, the generated html will be the following (I show only the first 2 items):

Expand|Select|Wrap|Line Numbers
  1.   <table  cellpadding="0px" cellspacing="0">                             
  2.            <tr style="height:50px">             
  3.              <td> 
  4.                 <div id="titleContainer" onmouseover="ShowEditButtons('pnlEditButtons');" style="position:absolute;">    
  5.                      <a id="lnkTitle" style="float:left;padding-right:10px;">1</a>             
  6.                      <div id="pnlEditButtons" style="vertical-align:middle;z-index:100;display:none;float:left;">                                                                                                
  7.                        <input type="image" name="imgbtn1" id="imgbtn1" src="Images/misc/edit.png" style="border-width:0px;" />                    
  8.                        <input type="image" name="imgbtn2" id="imgbtn2" src="Images/misc/Rename.png" style="border-width:0px;" />                                       
  9.                     </div>                                              
  10.                 </div> 
  11.             </td>               
  12.            </tr> 
  13.  
  14.            <tr style="height:50px">             
  15.              <td> 
  16.                 <div id="titleContainer" onmouseover="ShowEditButtons('pnlEditButtons');" style="position:absolute;"> 
  17.  
  18.                      <a id="lnkTitle" style="float:left;padding-right:10px;">2</a>             
  19.                      <div id="pnlEditButtons" style="vertical-align:middle;z-index:100;display:none;float:left;">                                                                                                
  20.                        <input type="image" name="imgbtn1" id="imgbtn1" src="Images/misc/edit.png" style="border-width:0px;" />                    
  21.                        <input type="image" name="imgbtn2" id="imgbtn2" src="Images/misc/Rename.png" style="border-width:0px;" />                                       
  22.                         </div>                                              
  23.                  </div> 
  24.               </td>               
  25.            </tr> 
As you can see all divs get the SAME ID, THIS I DONT WANT!!!

But If I omit this line form the ItemCreated event:

Expand|Select|Wrap|Line Numbers
  1. containerPanel.Attributes.Add("onmouseover", "ShowEditButtons('" + editButtonsPanel.ClientID + "');"); 
The generated HTML will be the following:

Expand|Select|Wrap|Line Numbers
  1. <table  cellpadding="0px" cellspacing="0">                             
  2.            <tr style="height:50px">             
  3.              <td> 
  4.                 <div id="rptThreads_ctl01_titleContainer" style="position:absolute;"> 
  5.  
  6.                      <a id="rptThreads_ctl01_lnkTitle" style="float:left;padding-right:10px;">1</a>             
  7.                      <div id="rptThreads_ctl01_pnlEditButtons" style="vertical-align:middle;z-index:100;display:none;float:left;"> 
  8.  
  9.                        <input type="image" name="rptThreads$ctl01$imgbtn1" id="rptThreads_ctl01_imgbtn1" src="Images/misc/edit.png" style="border-width:0px;" />                    
  10.                        <input type="image" name="rptThreads$ctl01$imgbtn2" id="rptThreads_ctl01_imgbtn2" src="Images/misc/Rename.png" style="border-width:0px;" />                                       
  11.                 </div>                                              
  12.               </div> 
  13.             </td>               
  14.            </tr>                 
  15.            <tr style="height:50px">             
  16.              <td> 
  17.                 <div id="rptThreads_ctl02_titleContainer" style="position:absolute;">    
  18.                      <a id="rptThreads_ctl02_lnkTitle" style="float:left;padding-right:10px;">2</a>             
  19.                      <div id="rptThreads_ctl02_pnlEditButtons" style="vertical-align:middle;z-index:100;display:none;float:left;"> 
  20.  
  21.                        <input type="image" name="rptThreads$ctl02$imgbtn1" id="rptThreads_ctl02_imgbtn1" src="Images/misc/edit.png" style="border-width:0px;" />                    
  22.                        <input type="image" name="rptThreads$ctl02$imgbtn2" id="rptThreads_ctl02_imgbtn2" src="Images/misc/Rename.png" style="border-width:0px;" />                                       
  23.                         </div>                                              
  24.                 </div> 
  25.              </td>               
  26.            </tr> 
All divs get unique IDs, and this I do want

My questions are:
1)why it happens? why this line of code messup the ids?
2)how can have the unique ID's and assign javascript in codebehind?
I can add this on aspx (it will wotk and I will get unique ids):

Expand|Select|Wrap|Line Numbers
  1.  onmouseover='<%# "javascript:ShowEditButtons(\""+ Container.FindControl("pnlEditButtons").ClientID+ "\");" %>'  
But I must do it in codebehind because I need to set the javascript only if server validate some things.
Apr 2 '10 #1
1 4063
Frinavale
9,735 Recognized Expert Moderator Expert
You're doing things correctly.
Something is messing up your IDs and I think it's the PlaceHolder.
You don't need the Placeholder so try deleting it and see if this fixes things.

-Frinny
Apr 5 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3269
by: Stephen Miller | last post by:
I am using the OnItemDataBound event of Repeater control to nest a DataGrid within the Repeater. When I attempt to bind to the DataGrid using the DataSource method I get the error message "Object...
7
1983
by: Scott Schluer | last post by:
Hi All, I have a functioning datagrid on "Page 1" that displays order information for a single order (this is for an e-commerce site). It's actually a combination of a couple datagrids to...
1
3443
by: Ravi | last post by:
Hi, I have a radio button list and a dropdownlist inside a repeater control. Want to hide or display the dropdownlist based on selection in radiobuttonlist. I can add the...
3
6673
by: JD | last post by:
Hello, I have a problem with checkboxlist inside Repeater (in ASP.NET page). I am able to create Checkboxlist and bind it (inside Repeater_ItemBound - including setting checked/unchecked)....
1
2909
by: Keith Harris | last post by:
Hi, I have a Repeater control which is bound to a dataset. In the footer of the repeater control, I have a Button whose visibility I want to vary according to the sum of a column being > 0. ...
0
10466
by: datakix | last post by:
After 16 hours of frustration, I've managed to solve this problem for a project I'm working on. The 'trick' is set EnableViewState="False" for the asp:textbox inside the Repeater control. The...
0
1070
by: Ashok | last post by:
Hi I have some issues in applying Themes to controls programatically, when controls are inside WebpartZone. I have put some controls inside WebpartZone, i want to apply themes and skin to those...
4
1344
by: volkmar rigo | last post by:
hi. is there a way to access the controls of a repeater template at runtime? i tried the GetFields method to extract all the controls of the repeater as FieldInfoArray but that array contails...
1
2264
by: Řyvind Isaksen | last post by:
I have a Repeater that dynamicly displayes some textboxes. Each Textbox has an ID like this (example): ID="10_20_textbox". The first number (10) describes what article this field is for, and the...
0
7233
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
7135
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
7342
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,...
1
7067
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...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5650
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,...
0
3215
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...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.