Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

javascript referencing items within a Repeater?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
HockeyFan - 02 Aug 2007 16:52 GMT
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?
Teemu Keiski - 02 Aug 2007 17:14 GMT
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 examplöe 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.

Signature

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

> Yesterday, I posted a question dealing with an issue of trying to
> reference (from javascript on the client side) an item within a
[quoted text clipped - 4 lines]
> rendered in html are they?  What method do other .Net developers use
> to reference a control on a RepeaterItem when doing it from javascript?
HockeyFan - 02 Aug 2007 17:21 GMT
Outstanding.  Thanx

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.