Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a bunch of functions that are used across multiple ASPX files. I want to condense these down to one file to be used for all the ASPX files. I have a few ideas but I want to know what the accepted method to doing this would be. I have an idea to just create a class to put them in.

However, I was wondering if i could put them in a ascx page, but that does not look like the solution I'm looking for.

Is there a accepted method for this type of situation?

share|improve this question
up vote 4 down vote accepted

Sure it can be done by creating a library in the project, and referencing the namespace in your aspx files.

<%@ Import Namespace="sharedfunctionlibrarynamespace" %>

I also found a similar post - Reusing same functions in different .aspx files/making function library

As you have also mentioned, another approach is to create a base class from which all of your page classes will derive. That will work as well.

share|improve this answer
Thanks for your response. Do you see any benefit to creating a library over just using a base class? – DFord Jul 3 '12 at 19:14
I would look at the trade-offs. Base-class approach might be useful if you use this functions only in one module(sub-domain). However, having them as a separate library, would allow reuse in other sub-domains as well, where your classes do not inherit from base class. – Yusubov Jul 3 '12 at 19:25
Thank you for the help, I will keep that in mind. – DFord Jul 3 '12 at 20:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.