how to pass a web app page reference (specific instance)?

  • Thread starter Thread starter Rob R. Ainscough
  • Start date Start date
R

Rob R. Ainscough

ASP.NET with VB.NET using 2.0 framework

I've created a class (myClass) under App_Code specific to my web
application.

I have a method in myClass called Display:

Public Function Display(ByRef aWebPage As Web.UI.Page) As Boolean

Select Case aWebPage.Page.ToString
Case "ASP.CustomerValidation"

End Select

End Function

What I would rather do is overload the Display function using specific page
references contained in my web application.

Public Overloads Function Display(ByRef CustomerPage as ????) As Boolean
.....

Public Overloads Function Display(ByRef PaymentPage as ???) As Boolean
.....

assume I have a a CustomerPage.aspx and a PaymentPage.aspx in my web
application

How do I make direct references to this pages from the myClass.Display()
method?

Thanks, Rob.
 
dont really understand what your asking. you kind of answered your own
question

Public Overloads Function Display(ByRef CustomerPage as CustomerPage)
As Boolean

Public Overloads Function Display(ByRef CustomerPage as PaymentPage) As
Boolean

You would just pass the types of those pages to the different
functions.

What code will be executed under Display()? Depending on what your
doing, you could create an abstract class/interface, and then cast pass
the pages as your interface/abstract class. This would utilize
polymorphism
 
The problem is I can't get myClass.Display method to identify the specific
web page reference of my web application (i.e. as CustomerPage) -- I can
only reference the generic type Web.UI.Page from the myClass.Display method.

Probably missing something simple, but don't know what.

The class (myClass) resides in my web application under the App_Code
directory but it can't see to see any of my web page references (i.e.
CustomerPage, PaymentPage). I tried to qualify it with
MyWebAppName.CustomerPage but not such reference was available in MyClass.

Rob
 
what does the namespace declaration look like in CustomerPage and
PaymentPage? Are the classes and aspx pages in the same namespace? if
not, import the namespace at the top of myClass
 
Apparently VS 2003 supported this concept of specific web page reference
from a class within the same web app. However, it turns out that VS 2005
does NOT support this now (something to do with it being a compiled
process) -- my only options would be to put all my .aspx pages in the
App_Code dir, however, this would then drop some of the functionality I get
from other aspects of VS 2005 code behind.

Web pages in VS 2005 are setup as "Partial Class". The aspx pages and the
class is under the same web project but there is no namespace defined for
the web pages. But if you can confirm this just do this:

1. Create new web projects/solution
2. Add web page
3. Add a class -- you will have to place it in App_Code dir (VS 2005 will
be prompt you)

Now try to reference the web page from within your new class. If you find a
way to do this, please share.

Oh well, one step forward, two steps back.

Rob.
 
You could do like they mentioned and use an abstract base class, then
have a switch statement for each type, although this is not OOP and
even the idea of it is making me cringe :)

I'm suprised that MS would do something like this that cripples certain
features that are required to do proper OOP programming
 
Cost of "improved performance" I guess -- I would rather avoid thinking
about what MS do and don't do -- either road leads to frustration for me, so
I just take the good with the bad and hope there is more good than bad. So
far, VS 2005 is marginally better than VS 2003. Q3 is a long wait to fix
many of the current VS 2005 issues, but this is one of those "by design"
issues that doesn't qualify.
 

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

Back
Top