0

Following is my page & control hierarchy.

Page
  UserControl 1
    <Repeater1> //Contents of UserControl 1
      UserControl 2
        <Accordion> //Contents of UserControl 2
        <Header/>
        <Content>
           <Repeater2/> //Repeater 2 is within Usercontrol 2
        <Button/>    // Button is within Usercontrol2, not Repeater 2
         </Accordion>
     </Repeater1>

I need to be able to refresh the Repeater2 upon Button click.

Any pointers will be really helpful.

spraman
  • 3
  • 2

1 Answers1

0

Attach an event to the click of the button. Inside that event, you should be able to traverse the control hierarchy to get to repeater2.

Button theButton = sender as Button;
UserControl2 parentControl = theButton.Parent as UserControl2;

Repeater theRepeater = null;
foreach(Control control in parentControl.Controls){
    theRepeater = control as Repeater;
    if(theRepeater != null) break;
}
Arbiter
  • 984
  • 1
  • 10
  • 24
  • Thanks, let me try this out. Also i forgot to mention that I've an UpdatePanel in UserControl2 surrounding the whole of Accordion. Is that a preferred way? – spraman Jan 03 '12 at 17:34
  • So long as you have children as triggers on the update panel you should be fine. Using the update panel makes it easier for you as a developer, but it's going to be heavy (viewstate still gets passed around). Using page methods or ASMX script services with JSON templates and JQuery would be the slickest way to do this, albeit more work for you. – Arbiter Jan 03 '12 at 17:47
  • You're right. Also I find that the datasource has to be bound each time though it does a partial page refresh which is an overhead for me. And I guess its not possible to just refresh an item in Repeater1 standalone using UpdatePanel, which would require me to fetch the whole data again and bind it. Would appreciate if you can point me to right resources on using page methods or ASMX script services. Thanks. – spraman Jan 03 '12 at 17:55
  • If you can bind all your data before you return the page you can use javascript and client effects (see JQuery UI) to create the "accordion" effect you're looking for. Otherwise, this is some info about [script methods](http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-web-services) here. If you need to dynamically build HTML in javascript [this video](http://www.pluralsight-training.net/microsoft/players/PSODPlayer?author=scott-allen&name=mvc3-building-ajax&mode=live&clip=0&course=aspdotnet-mvc3-intro) (click JQuery templates) is good. – Arbiter Jan 03 '12 at 18:15