Quantcast
Channel: CSharp Forum Latest Questions
Viewing all articles
Browse latest Browse all 32120

List out all controls in a form

$
0
0
Hi all I am trying for a solution where I need to traverse through each and every from in my application and need to list out the controls which is not having associate control id for this I tried the following way first 

 Page p = BuildManager.CreateInstanceFromVirtualPath("/" + "test.aspx", typeof(Page)) as Page;
((IHttpHandler)p).ProcessRequest(HttpContext.Current);

                        ControlCollection lCollection = p.Controls;

Which is working a expected but the page which I am calling in that virtual path is getting added to the current page, how can I stop adding this.

The other one I tried is 

string filePath = System.Web.HttpContext.Current.Request.PhysicalApplicationPath;
                filePath = filePath + "test.aspx";
 using (StreamReader sr = new StreamReader(filePath))
                {
                    MessageBody = sr.ReadToEnd();
                }

From the MessageBody I need to list out all the controls using some Regex, is this possible can some one help me to achieve my task

Viewing all articles
Browse latest Browse all 32120

Trending Articles