Read controls of a Page

May 9 2008 8:19 AM

Hi, I'm trying to read the controls of a web Page from a class. I found a way to do it but it only works when the code it's part of the page. When I do it from the class the collection of controls comes empty like nothing it's on the page.

If anyone could help to do this, i'll apreciate it... By the way i'm trying to make a security dll that reads the controls of the page and then the user can determine which controls are going to shown to the diferent level of access...

This is the code a wrote:

public void DetectarForms(String Ruta)

{

   Assembly assembly = Assembly.LoadFrom(Ruta);

   foreach (Type type in assembly.GetTypes())

   {

      if (type.BaseType.ToString() == "System.Web.UI.Page")

      {

         Page Pagina = (Page)assembly.CreateInstance(type.FullName);

         Control Controles = (Control)assembly.CreateInstance(type.FullName);

         bool bln = Controles.HasControls();

         if (Pagina.Form != null)

         {

            foreach (Control ctrl in Pagina.Form.Controls)

            {

               String str = ctrl.GetType().ToString();

            }

         }

      }

   }

}

 

Thanks in advanced...