Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 10th, 2007, 08:52 AM
Authorized User
 
Join Date: Jun 2005
Location: Nashville, TN, USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jayahar Send a message via Yahoo to Jayahar
Default Accessing Child Controls of Nested Repeater...

Hi All,

     I'm using a nested repeater control, where the inner repeater has a web usercontrol bound to it. The web usercontrol is placed inside the itemtemplate of the inner repeater. There are few textboxes and dropdowns in the usercontrol. I have to get the values of these controls and update a dataset. Could anyone say, how I can access the controls in the web usercontrol.



Any input is appreciated.

Jay
__________________
Regards,
Jayahar Aruchamy.
Life is all about expecting the unexpected.
  #2 (permalink)  
Old October 10th, 2007, 09:28 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Can you access the user control itself? If so then accessing the controls within it is a matter of exposing those controls (or properties of those controls) publicly in the user control class. It's better practice to expose the properties of the controls instead of the controls themselves so the controls remain truly encapsulated.

For example, you would expose the .Text property of an encapsulated textbox to provide public access to this user control's email address:

public partial class MyUserControl : System.Web.UI.UserControl
{
   protected TextBox txtEmailAddress;

   public string EmailAddress{
      get{ return txtEmailAddress.Text; }
      set{ txtEmailAddress.Text = value; }
   }
}

-Peter
  #3 (permalink)  
Old October 11th, 2007, 10:32 AM
Authorized User
 
Join Date: Jun 2005
Location: Nashville, TN, USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jayahar Send a message via Yahoo to Jayahar
Default

Thanks Peter,

     But, I'm not able to access the user control itself. Accessing the user control is the big task for me now.

-Jay

Regards,
Jayahar Aruchamy.
Life is all about expecting the unexpected.
  #4 (permalink)  
Old October 11th, 2007, 01:24 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Usually you would access a control inside a repeated item during an event related to the item itself, such as ItemDataBound or ItemCreated. The event names vary by control but follow the same general naming pattern. The handler is passed an event args class that has the item itself as a member.

For example:

Inside your item template you have a textbox:

   <asp:textbox runat="server" id="myTextBox" ... />

Within the event handler you can get the template's control instance from the item like this:

   TextBox myTextBox = (TextBox)e.Item.FindControl("myTextBox")
   //Use the myTextBox instance to do what you want.

The same technique can be applied to instances of your user control. You just need to find the control by name and convert it to the correct type to get at the control's members.

-Peter


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested Repeater Using Stored Procedure kwilliams ASP.NET 2.0 Professional 1 July 21st, 2008 06:49 PM
nested repeater ramonjor ASP.NET 2.0 Basics 0 July 31st, 2007 04:18 AM
FindControl in nested repeater chrisk_47 .NET Framework 2.0 0 February 6th, 2007 10:45 PM
nested repeater david_ste ASP.NET 2.0 Professional 0 August 24th, 2006 09:52 AM
Accessing the MDI form controls from child forms krishnasamaga Visual Studio 2005 1 June 7th, 2006 08:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.