473,320 Members | 1,939 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Add a global class .cs file

35
Hello,
I want to create a c# file with shared classes for my application and I want to include it at the application level so that my classes will be avialabe throught all of my pages.

I have considered just adding all of my classes to the code behind file of the masterpage but since that has specific logic to the page built into it I would realy prefer to seperate out the global classes from any page specific logic.

So I'm thinking there should be a way in the web config to just say like <include myfile.cs>

Your help is appriciated

Thankyou
Jun 21 '07 #1
3 1742
Plater
7,872 Expert 4TB
Just add a class file (*.cs) to your project with VS, it will tell you something to the effect of "you must put this class in the "App_Code" directory in order to be useful". Just put your classes there (no need for namespaces unless you want them) And you can then use the classes from anywhere in the web application.
Jun 21 '07 #2
rojiin
2
Just add a class file (*.cs) to your project with VS, it will tell you something to the effect of "you must put this class in the "App_Code" directory in order to be useful". Just put your classes there (no need for namespaces unless you want them) And you can then use the classes from anywhere in the web application.

Please tell me how to call that (.cs) file in our application.please provide me with an example
Jul 5 '07 #3
Plater
7,872 Expert 4TB
Mmm are you familiar with C#/VB at all? If not, I would suggest doing a quick check for a basics tutorial.
The way the classes are used are exactly the same in a windows application vs a web-based application.

If you have a class:
Expand|Select|Wrap|Line Numbers
  1. public class myclass
  2. {
  3.    public myclass()
  4.    {
  5.       //constructor stuff
  6.    }
  7.    public int myfunc(int a)
  8.    {
  9.       return a+1;
  10.    }
  11. }
  12.  
Then in your web you can instantiate the class like normal with:
Expand|Select|Wrap|Line Numbers
  1. myclass mc= new myclass();
  2. int b=2;
  3. mc.myfunc(b);//returns a 3
  4.  
Jul 5 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tony Johansson | last post by:
Hello! I'm reading a book about C++ and there is something that I don't understand so I ask you. Below I have the text from the book and the code from the file where main is located and some...
22
by: fd123456 | last post by:
Hi Tom ! Sorry about the messy quoting, Google is playing tricks on me at the moment. > Global.asax is where you normally have the Global Application > and Session variables and code to...
9
by: tshad | last post by:
I have an example I copied from "programming asp.net" (o'reilly) and can't seem to get the Sub (writefile) to execute. It displays all the response.write lines that are called directly, but not...
15
by: randyr | last post by:
I am developing an asp.net app based on a previous asp application. in the asp applications global.asa file I had several <object id="id" runat="server" scope="scope" class="comclass"> tags for...
2
by: Nathan Sokalski | last post by:
I would like to access variables and functions that I declare in the Global.asax.vb file. However, I am having trouble doing that. What does the declaration have to look like in the Global.asax.vb...
8
by: Thomas Coleman | last post by:
Ok, I've obviously discovered that Global.aspx has been completely changed in ..NET 2.0. However, I haven't figured out how to declare a constant that's available to any page in my application...
7
by: Adam | last post by:
Im trying to add an httphandler for all *.sgf file extensions. I have developed the handler, 1. installed it into the gac 2. added it to the machine.config: <httpHandlers> <add verb="*"...
11
by: Ron | last post by:
I have a web project compiled with the new "Web Deployment Projects" plugin for VS2005. I'm deploying the web project to one assembly and with updateable option set to ON. When I'm running the...
8
by: Rob T | last post by:
When I was using VS2003, I was able to compile my asp.net project locally on my machine and copy it to the production server and it would run just fine. I've now converted to VS2005. The project...
15
by: =?Utf-8?B?UGF0Qg==?= | last post by:
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax code file. In 1.1 I could have a code behind file for the global.asax file. This allow for shared variables of the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.