call a public method in aspx.cs file from another web page

M

Mike

I have an web page (page1.aspx) that has a method in the code behind that I want to call from another page. Is this possible to do?

The method resides in the page1.aspx.cs file, its a public method, is there a way I can call that method from another web page?

Page2.aspx.cs needs to call Public Void GetCars() in Page1.aspx.cs - is this possible?
 
M

Mark Rae [MVP]

I have an web page (page1.aspx) that has a method in the code behind that
I want to
call from another page. Is this possible to do?

The method resides in the page1.aspx.cs file, its a public method, is
there a way I can
call that method from another web page?

Page2.aspx.cs needs to call Public Void GetCars() in Page1.aspx.cs - is
this possible?

It is possible - you just instantiate the class behind Page1 just as would
instantiate any other class...

However, this is almost certainly bad design...

The partial class behind an aspx page is best used for functionality which
relates specifically to that page. If you have functionality which needs to
be used by more than one aspx page, the best solution would be to take it
out of Page1.aspx.cs and place it in a separate class...
 

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

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top