Step 1. All the Page Names in Dropdown
Add ddlPageNames Dropdown on aspx Page
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[] filePaths = Directory.GetFiles(@"D:\WebSite1\", "*.aspx");
foreach (String item in filePaths)
{
char c = '\\';
String[] Filter = item.Split(c);
ddlPageNames.Items.Add(Filter[2]);
}
}
}
Step 2. Create a Sample Page where you can load another page with in using iFrame Object and Collect all the Control Properties and Save them into Session.
<p>
<iframe id="I1" runat="server" name="I1" width="0" height="0" src="Default.aspx" visible="true">
</iframe>
<asp:DropDownList ID="ddlPageNames" runat="server" AutoPostBack="true" onselectedindexchanged="ddlPageNames_SelectedIndexChanged"></asp:DropDownList>
<asp:Button ID="btnListControls" runat="server" Text="Button" onclick="Button1_Click" />
<asp:Label ID="TotalControls" runat="server"></asp:Label>
<asp:GridView ID="GridView1" runat="server"
onpageindexchanged="GridView1_PageIndexChanged"
onpageindexchanging="GridView1_PageIndexChanging"
onrowdatabound="GridView1_RowDataBound" >
</asp:GridView>
</p>
protected void btnListControls_Click(object sender, EventArgs e)
{
DataView dt;
dt = (DataView)Session["dtData"];
if (dt != null)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void ddlPageNames_SelectedIndexChanged(object sender, EventArgs e)
{
I1.Attributes["src"] = Convert.ToString(ddlPageNames.SelectedValue);
}
Step 3. Now Bind the Stored Control Names into Gridview to List all.
For Instance :
Suppose You Want to List all Controls Available on Default.aspx Page then Follow
DataTable dt = new DataTable();
DataView objDV = new DataView();
protected void Page_Load(object sender, EventArgs e)
{
dt.Columns.Add("Ctrl", typeof(string));
dt.Columns.Add("Name", typeof(string));
foreach (Control ParentMain in Page.Controls)
{
#region //CurrentPage
Page objpage = new Page();
string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
string sRet = oInfo.Name;
foreach (Control Child1 in ParentMain.Controls)
{
FillControlList(Child1);
foreach (Control Child2 in Child1.Controls)
{
FillControlList(Child2);
if (Convert.ToString(Child2.ID) == "GridView1")
{
GridView myGridView1 = (GridView)Page.FindControl("GridView1");
}
#region
foreach (Control Child3 in Child2.Controls)
{
FillControlList(Child3);
if (Convert.ToString(Child3.ID) == "Button1")
{
Child3.Visible = false;
}
foreach (Control Child4 in Child3.Controls)
{
FillControlList(Child4);
if (Convert.ToString(Child4.ID) == "Button1")
{
Child4.Visible = false;
}
foreach (Control Child5 in Child4.Controls)
{
FillControlList(Child5);
if (Convert.ToString(Child5.ID) == "Button1")
{
Child5.Visible = false;
}
}
}
}
#endregion
}
}
#endregion
}
objDV = dt.DefaultView;
Session["dtData"] = objDV;
}
Next
public void FillControlList(Control Ctrl)
{
ListItem li = new ListItem();
li.Text = Convert.ToString(Ctrl.ID);
li.Value = Convert.ToString(Ctrl.ID);
if (!string.IsNullOrEmpty(Convert.ToString(li.Text)))
{
DataRow row = dt.NewRow();
row["Ctrl"] = Ctrl.ID;
dt.Rows.Add(row);
dt.Rows[dt.Rows.Count - 1][1] = Ctrl.GetType().Name;
}
}