The method DisplyDetails you provide is private and therefore available only to Page1
If you want to call it from Page2, you should either make it public and instantiate page1 in page2 or make it static (but then you cannot use instance variables).
I would suggest pulling the method out in one of business logic classes and calling it from there:
Public Class DetailManager
private Control page;
DetailManager(Control page){
this.page = page;
}
{
public List<control> DisplayDetails () {}
}</control>
in page(s) code
DetailManager dm = new DetailManager(this)
dm.DisplayDetails()
You should return collection of controls with their properties, rather then writing directly on the output in the page and returning void.
Also, it seems you're simply getting Text from the controls that have that property...why not enumerate the controls and simply ask for their Text property instead of getting all properties. There are recursive functions to go through all your controls and get only those of given type.
Like this:[
^]
public static IList<T> GetAllControlsRecusrvive<T>(Control control) where T :Control
{
var rtn = new List<T>();
foreach (Control item in control.Controls)
{
var ctr = item as T;
if (ctr!=null)
{
rtn.Add(ctr);
}
else
{
rtn.AddRange(GetAllControlsRecusrvive<T>(item));
}
}
return rtn;
}
If this helps, please take time to accept the solution. Thank you.