Wednesday, August 29, 2012

Dynamically Accessing MainPage controls in child UserControl's from codebehind in metro application?

Dynamically Accessing MainPage controls in child UserControl's from codebehind in metro application?

i have a MainPage in which part of the screen i have empty grid named customview , in which i want to dynamically add and remove different views(different usercontrols). now i have attached one usercontrol(view1) to that empty grid(part of the MainPage) in this way :- customview is the empty grid , view1 is the usercontrol which i have designed,and on navigated to MainPage i am doing this :-

protected override void OnNavigatedTo(NavigationEventArgs e) { customview.Children.Clear(); View1 firstview = new View1 (); customview.Children.Add(firstview);  } 

Now , View1 (usercontrol) is having a button1 , on that button1 click i have to remove view1 and add view2 (another user control) to the same grid named customview present in MainPage.

which i have tried it in this way but no luck :-

private void button1_Click_1(object sender, RoutedEventArgs e) { MainPage main = new MainPage(); View2 secview = new View2 (); Grid grd = main.FindName("customview") as Grid; grd .Children.Clear(); grd .Children.Add(secview); } 

Please let me know where am i doing wrong ? Thanks in advance.

Answers & Comments...

Answer: 1
Label lbl = (Label)this.Page.FindControl("controlID"); string labelText = lbl.Text; 
by : Ankush Jainhttp://stackoverflow.com/users/1372444




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog