reflection in web pages

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Naim

    #1

    reflection in web pages



    Hi all,

    I need to iterate through web pages controls using reflection.

    However when I create an instance of the web page, the controls
    collection is empty.
    Can anyone help ?

    here's the code used:

    Dim myAssembly As System.Reflecti on.Assembly
    myAssembly = myAssembly.Load ("App_Web")
    Dim definedTypes As Type() = myAssembly.GetT ypes
    Dim myType As Type
    For Each myType In definedTypes
    Dim myPage As System.Web.UI.P age
    Dim j As Integer
    If myType.BaseType .Name = "Page" Then
    myPage = myAssembly.Crea teInstance(myTy pe.FullName)
    Debug.WriteLine ("myPage.Contro ls.Count=" +
    myPage.Controls .Count.ToString )
    For j = 0 To myPage.Controls .Count - 1
    'Do something
    Next
    End If
    Next


    *** Sent via Developersdex http://www.developersdex.com ***
  • Henning Krause [MVP - Exchange]

    #2
    Re: reflection in web pages

    Hello,

    the controls of the page are created during the normal page lifecycle (by
    calling CreateChildCont rols).

    Why do you want to parse through your own instance of a class? Maybe there
    is a better way to achieve what you want to do.

    Best regards,
    Henning Krause

    "Naim" <anonymous@devd ex.comwrote in message
    news:eFVUh%237l HHA.4152@TK2MSF TNGP04.phx.gbl. ..
    >
    >
    Hi all,
    >
    I need to iterate through web pages controls using reflection.
    >
    However when I create an instance of the web page, the controls
    collection is empty.
    Can anyone help ?
    >
    here's the code used:
    >
    Dim myAssembly As System.Reflecti on.Assembly
    myAssembly = myAssembly.Load ("App_Web")
    Dim definedTypes As Type() = myAssembly.GetT ypes
    Dim myType As Type
    For Each myType In definedTypes
    Dim myPage As System.Web.UI.P age
    Dim j As Integer
    If myType.BaseType .Name = "Page" Then
    myPage = myAssembly.Crea teInstance(myTy pe.FullName)
    Debug.WriteLine ("myPage.Contro ls.Count=" +
    myPage.Controls .Count.ToString )
    For j = 0 To myPage.Controls .Count - 1
    'Do something
    Next
    End If
    Next
    >
    >
    *** Sent via Developersdex http://www.developersdex.com ***

    Comment

    • Naim

      #3
      Re: reflection in web pages



      hi Henning,
      Thank you for your answer.
      we need to generate a global resource file for all the webpages. VS2005
      give us the ability to generate a local ressource file for each webpage
      automatically however unfortunately this doesn't suit us very well. We
      want to develop something similar but that generates one ressource file
      for all web pages.
      Do you know if there's a tool that can accomplish this, or do you have
      an idea about how to do it.

      Thank you
      Naim

      *** Sent via Developersdex http://www.developersdex.com ***

      Comment

      Working...