I have a page, Default.aspx, with its own code-behind file like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
public int[] anArray;
...
}
What I’d like to do is access to “anArray” from a C# class (not tied to a page) declared in \App_Code folder. What can I do?
Thanks.
Edit: As said in the first comment, I really apreciate your suggestions about refactoring my connection objects. However, what I’m really doing here is to rewrite an old PHP application in order to get comfortable with basic C# and ASP.NET, so this code will never go really live. So, I’m still intersted in a way (if any) to access an object declared in a code-behind code from a standard C# class.
Edit2: I removed the OdbcConnection object in order to focus to the real problem: how to refer to an object istantiated in a code-behind file from a C# class situated in \App_Code?
The problem is the you are adding classes to the APP_Code folder. Generally, these are not compiled in with the website, but are compiled into their own dll which is referenced by the Website dll.
Generally, what I do, since I hate that little caveat, is create a folder in the Website project called Code, and use that instead of the App_Code folder.
Out of curiosity, what version of Visual Studio are you using?