DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Thu, 02 Aug 2007 08:52:39 -0700,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    HockeyFan
          2    Teemu Keiski
          3    HockeyFan


javascript referencing items within a Repeater?   
Yesterday, I posted a question dealing with an issue of trying to
reference (from javascript on the client side) an item within a
Repeater.  My code was hard-coded to use the actual ClientId, but
someone admonished me, stating that I shouldn't do that because the id
could change.  However, since I'm trying to reference a control on a
Repeater line, I'm wondering how else to do that.  Repeaters aren't
rendered in html are they?  What method do other .Net developers use
to reference a control on a RepeaterItem when doing it from javascript?
Date:Thu, 02 Aug 2007 08:52:39 -0700   Author:  

Re: javascript referencing items within a Repeater?   
Hi,

Repeaters do render but what you have specified them to. Pij t is to 
generate the script to access the controls on repeaterItem, at least 
generate an js array which contains the ClientIDs of the controls in the 
repeater

It can be done for example iterating Repeater's Items collection, calling 
FindControl against every RepeaterItem to get reference to the control on 
the item. Then you can access ClientID of these controls

I have availbale a sample which deals with gridView but idea is 100% same. 
item type is just RepeaterItem and you iterate Repeater's Items collection

 protected void GridView1_PreRender(object sender, EventArgs e)
        {
            StringBuilder sbScript = new StringBuilder();

            //I'm doing this in PreRender because RowDataBound happens only 
when databinding occurs - not necessarily on every request
            //and RowCreated is too early to get the correct client-side ID
            foreach(GridViewRow row in GridView1.Rows)
            {
                CheckBox CheckBox1 = (CheckBox)row.FindControl("CheckBox1");
                sbScript.Append("'");
                sbScript.Append(CheckBox1.ClientID);
                sbScript.Append("'");
                if(row.RowIndex != (GridView1.Rows.Count - 1))
                    sbScript.Append(",");

            }
            //Register the array
            Page.ClientScript.RegisterArrayDeclaration("checkBoxes", 
sbScript.ToString());
        }.

Previous example creates a javascript array named checkBoxes cointaining 
reference of CheckBoxes with CheckBox1 on every GridViewRow. You can then 
use these array at client to reference the checkboxes there.


-- 
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net



"HockeyFan"  wrote in message 
news:1186069959.357408.35420@m37g2000prh.googlegroups.com...

> Yesterday, I posted a question dealing with an issue of trying to
> reference (from javascript on the client side) an item within a
> Repeater.  My code was hard-coded to use the actual ClientId, but
> someone admonished me, stating that I shouldn't do that because the id
> could change.  However, since I'm trying to reference a control on a
> Repeater line, I'm wondering how else to do that.  Repeaters aren't
> rendered in html are they?  What method do other .Net developers use
> to reference a control on a RepeaterItem when doing it from javascript?
> 
Date:Thu, 2 Aug 2007 19:14:27 +0300   Author:  

Re: javascript referencing items within a Repeater?   
Outstanding.  Thanx
Date:Thu, 02 Aug 2007 09:21:45 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us