Problem enumerating pages in .NET 2.0

G

Gerry

Without bothering with the details (though if you are curious, I'll be
glad to explain!). This code functions perfectly under ASP.NET 1.1, but
randomly fails under ASP.NET 2.0. More details after the snippet

My site has the following web pages:
MainPage.aspx
Page1.aspx
Page2.aspx
Page3.aspx
Page4.aspx

The code behind file for MainPage looks like this:

Partial Class FinOpsCentral
Inherits System.Web.UI.Page

Dim appPages As New Hashtable

Private Sub Page_Load ...
appPages.Add(butPage1, "Page1")
appPages.Add(butPage2, "Page2")
appPages.Add(butPage3, "Page3")
appPages.Add(butPage4, "Page4")

If (Not IsPostBack) Then
Dim aspxPageType As Type
For Each pageObject As DictionaryEntry In appPages
aspxPageType = Type.GetType(pageObject.Value)
Next
End If
End Sub

....

End Class

By 'randomly fails', the GetType function will return Nothing on one of
the pages. If the solution is recomplied, GetType will return Nothing
for a page that (prior to recompiling) it returned its type.

The only difference between the 2.0 code and the 1.1 code is this:
Under 1.1, the GetType line read:

aspxPageType = Type.GetType("siteName." +
pageObject.Value)

I make heavy use of this construct in a number of my applications. It
works just fine for one of them (which has about six pages), but fails
on the others (which have about a dozen pages).

I haven't a clue as to why this is failing - I could really use your
help! Thanks.
 
B

Bruce Barker

in asp.net 1.1, the page codebehind files were built into one dll, and the
page (aspx code) dll referenced that dll thru inherence. this meant the
codebehind code of one page could reference the codebehind code of any page
as there are in the same dll.

in 2.0, the codebehind is compiled, thru partial classes into the page dll.
thus for a page to reference another page you have a couple options.

both 1.1 and 2.0 use a batch compile concept for pages, so several pages
are compiled into one dll. this is what causes your intermittent problems.
when the pages are compiled together it works, when a page gets it own dll
it doesn't.

1) use base pages in app dir and inherit (1.1 model).
2) use a utility to combine all page dll into one - requires custom build
step
3) if only one page needs references to others, just add a reference
directive in the aspx

-- bruce (sqlwork.com)
 
G

Gerry

Bruce,

Thank you for you suggestions. Of the three options, I found the third
to be most agreeable as only one page needs to reference the others.
Thus, I modified the code in MainPage.aspx so that it now looks like
this:

<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="MainPage.aspx.vb" Inherits="MainPage" %>
<%@ Reference Page="Page1.aspx" %>
<%@ Reference Page="Page2.aspx" %>
<%@ Reference Page="Page3.aspx" %>

etc.

Sadly, I am experiencing the same problem.

Did I not include the reference correctly?
Is there something else I forgot to do?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top