how does one website page class call methods in another page class?

S

Steve Richter

what with the website solution structure not having a namespace, how
does the class of one website .aspx page class reference the class of
another page in the same website?

I have two pages. _Default.aspx and Default2.aspx. How would I call a
static or instance method in Default2 from _Default ?

assuming the answer is to qualify with the namespace, the question is
what is the namespace of the two pages?

thanks,

-Steve


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Default2 page2 = new Default2( ) ; // ????????


}
}

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
}
 
T

Teemu Keiski

Pages can't call each other's instance methods directly since normally a
request doesn't involve two pages but only one, when the other page isn't
instantiated and accessible. Exception is with cross-page postbacks where
the source page is instantiated when it's accessed via PreviousPage property
on the target page and therefore source page's methods could be called.

This is where components etc come into play when you can create classes
which can be used from pages.

Static methods are a different beast but why putting then on the pages,
instead of on components?
 
S

Steve Richter

Pages can't call each other's instance methods directly since normally a
request doesn't involve two pages but only one, when the other page isn't
instantiated and accessible. Exception is with cross-page postbacks where
the source page is instantiated when it's accessed via PreviousPage property
on the target page and therefore source page's methods could be called.

This is where components etc come into play when you can create classes
which can be used from pages.

Static methods are a different beast but why putting then on the pages,
instead of on components?

I want to define a method in the page class that is used to redirect
to that page. This method accepts the arguments that are passed to
the page, setups those arguments in the QueryString and then calls
Page.Response.Redirect.

basically, I want to encapsulate all the logic that pertains to a page
in the page class.

All my asp.net 1.1 web apps worked this way and it worked out well for
me.

Can someone explain the reason for the removal of the namespace from
2.0 websites?

-Steve
 
T

Teemu Keiski

In v2.0 there's the new web site project structure where there is dynamic
compilation, which changes things a bit. Pages are compiled on-demand, not
beforehand like in previous version (obvious when you work with VS2003), and
they can end up being compiled on different assemblies (dlls)

However, with VS2005 there is also web application project option which
works the same things worked with VS2003 and with that things work
similarly. One dll, and types available project-wide.

See: http://www.code-magazine.com/Article.aspx?quickid=0609061 for
background on changes


--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
 
B

bruce barker

you are confusing namespace with assemblies.

in 1.1 the codebehind files where compiled into 1 assembly. because all
the codebehind's where in 1 assembly they could call each other without
needing to supply a reference. note: the aspx page code was compiled
into a separate dll.

in a 2.0 web site the codebehind is compiled into the page dll, not a
common dll. for a page to call another page, you need to add a reference
to the otherpage. unfortunately .net does not support cross references
(for example assembly1 referencing assembly2 and assemply2 referencing
assembly1). this will cause your model to break down.

the correct way is to implement a navigation object in the app code folder.

you can download the web application project hack for 2.0, that follows
the 1.1 model of compiling the code behind files in a common assembly.

-- bruce (sqlwork.com)
 
S

Steve Richter

you are confusing namespace with assemblies.

in 1.1 the codebehind files where compiled into 1 assembly. because all
the codebehind's where in 1 assembly they could call each other without
needing to supply a reference. note: the aspx page code was compiled
into a separate dll.

in a 2.0 web site the codebehind is compiled into the page dll, not a
common dll. for a page to call another page, you need to add a reference
to the otherpage. unfortunately .net does not support cross references
(for example assembly1 referencing assembly2 and assemply2 referencing
assembly1). this will cause your model to break down.

the correct way is to implement a navigation object in the app code folder.

you can download the web application project hack for 2.0, that follows
the 1.1 model of compiling the code behind files in a common assembly.

hey, thanks for the answers. I dont like it, but that is ok. just
another reason to design my own web programming language some day ;)

( .aspx code is way too cluttered. very difficult to read. )

-Steve
 

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