473,386 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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)
{

}
}

May 3 '07 #1
6 12478
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?
--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
"Steve Richter" <St************@gmail.comwrote in message
news:11*********************@p77g2000hsh.googlegro ups.com...
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)
{

}
}
May 3 '07 #2
On May 3, 1:48 pm, "Teemu Keiski" <jot...@aspalliance.comwrote:
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

May 3 '07 #3
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...uickid=0609061 for
background on changes
--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net



"Steve Richter" <St************@gmail.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
On May 3, 1:48 pm, "Teemu Keiski" <jot...@aspalliance.comwrote:
>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
May 3 '07 #4
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)

Steve Richter wrote:
On May 3, 1:48 pm, "Teemu Keiski" <jot...@aspalliance.comwrote:
>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
May 3 '07 #5
KJ
I think web application projects are also included with VS2005 SP1.

On May 3, 3:42 pm, bruce barker <nos...@nospam.comwrote:
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)

Steve Richter wrote:
On May 3, 1:48 pm, "Teemu Keiski" <jot...@aspalliance.comwrote:
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

May 3 '07 #6
On May 3, 3:42 pm, bruce barker <nos...@nospam.comwrote:
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

May 3 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: David P. Donahue | last post by:
When I wrote websites in VB .NET, I would often put functions in Global for all the pages to call. Now, in C#, doing so results in "references to non-static objects" and whatnot. I realize what...
6
by: Mark | last post by:
I have been working for quite some time on this issue which in theory should be quite simple. The problem is that the Cancel and Save events are not fired when their respective buttons are...
1
by: magister | last post by:
hello I am putting together a web form which builds an xml file. I have another class which is referenced in the asp.net page. The first page load creates an instance of the class. In the class...
9
by: John Smith | last post by:
Hi, I have this problem. I have a page class in code behind called "WebForm1" and I have another class called "Class1". Now in Class1 I am creating ImageButton and I am adding event handler...
22
by: Brett Romero | last post by:
If my UI app uses three DLLs and two of those DLLs reference something named utilities.dll, does the UI app load utilities.dll twice or does the compiler recognize what is going on and load...
2
by: Rob Dob | last post by:
Hi, How do I go about installing another Web Site Project inside my existing VS2005 website project. I currently have both a forum WSP and my main WSP application within the same solution. Both...
18
by: cj | last post by:
members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe. I'm under the impression before you can use a class you have to make an...
2
by: David | last post by:
Hi all, using 1.1 I am creating a dynamic menu structure for my site, however, I may refer to the structure many times within a page. This would be fine if I was doing it all in the...
4
by: eBob.com | last post by:
In my class which contains the code for my worker thread I have ... Public MustInherit Class Base_Miner #Region " Delegates for accessing main UI form " Delegate Sub DelegAddProgressBar(ByVal...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.