[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Call aspx.cs from AppCode

Posted on 2008-06-11
4
Medium Priority
?
616 Views
Last Modified: 2013-12-17
Is it possible to call a method in aspx.cs from Class in AppCode?
0
Comment
Question by:johnkainn
  • 2
  • 2
4 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 21759027
read over this link:

http://www.velocityreviews.com/forums/t104413-20-appcode-folder-support-for-codebehind.html

if this is what yolu're talking about, the answer is yes.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 21759150
Hello johnkainn,

I don't think that link applies to you (and it is not best practice either as discussed in the thread).

The simple answer is unfortunately no. Partly because of the reasons indicated in the thread mentioned above. You cannot instantiate the partial class (aspx.cs) without loading the whole page. If you have a function that needs to be used both from a page and from another class then it is better for you to move that function out of the page and into a common class where it can be called from wherever is appropriate.

Regards,

TimCottee
0
 
LVL 21

Assisted Solution

by:silemone
silemone earned 400 total points
ID: 21760573
TimCottee's way would also work and i would use this method also.  you can sort of build your own library's by having your own classes.  

However, your question could it be done?  A resounding yes as shown by the link.  Should it be done?  Nothing wrong with it...just better to place methods in a class if you're going to use them constantly.  One of the major pluses of OOP is reusability.
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 600 total points
ID: 21760760
silemone,

The link you gave doesn't actually imply anything of the sort, all this talks about is whether it is possible to place code-behind files in the app_code folder (which it demonstrates is possible though not recommended). It doesn't in any way refer to any method for calling a function coded within that code-behind file from a class that is not part of the page that loads it.

TimCottee
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Loops Section Overview
Suggested Courses
Course of the Month17 days, 15 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question