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

  • Thread starter Thread starter Mike
  • Start date Start date
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?
 
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...
 
Back
Top