0

the index page I use is index.aspx and the c# class is called index.aspx.cs.

In the app_code folder I have another folder called "database" and within that folder is a .cs file called Query.cs

Now in the index.aspx.cs file I want to call the Query.cs class with the following code:

private Query query = new Query();

but it can't find Query.

What can I do?

6
  • Is Query the name of the class in that file? If so, is it public? Commented Dec 8, 2015 at 22:48
  • Maybe you're missing the namespace of the class... Commented Dec 8, 2015 at 22:49
  • The App_Code directory is special in ASP.NET and compiled at runtime, not design time. Program code contained within is only accessible from "code file" classes and .aspx files, not "code-behind" files Commented Dec 8, 2015 at 22:49
  • well, I can call the Query class in other .cs files in the app_code folder. Commented Dec 8, 2015 at 22:51
  • 1
    Try with the fully qualified name. Include the namespace: YourAppName.Query Commented Dec 8, 2015 at 22:53

1 Answer 1

2

See Below Example

Your App_Code Class File like below

public class Query
{
    public Datatable SelectData()
    {
        // Query Goes Here..
    }
}

Your index.aspx.cs file will be

//Create Object of Class
Query query = new Query();
Datatable dt = query.SelectData();
//Here Datatable is just considered for example

If you are calling class from another project you need give reference to that project.

Most of the times Access Modifiers are the issues in calling class members.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.