Click here to Skip to main content
16,017,100 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i wana know why .cs file is used in C# in asp.net and what is the basic purpose of this abc.cs file.
Posted

The .cs file is the code behind file for every class.
Code-behind files are files that are pre-compiled modules written in any of the Microsoft .NET runtime compliant languages.

These are the dll that are compiled and stored on the server (mostly in the app-code directory).

The code behind file is nothing but a partial class and was introduced in .Net 2.0.
To read more about code behind versus code inline have a look at Code Behind vs. Code Inline[^].
 
Share this answer
 
we will write logic code in cs file only...
the extension is .cs..
 
Share this answer
 
Comments
raj_sagoo 2-Sep-11 2:36am    
and how to add .cs file in asp.net project
Basically you will find two types of cs files in a asp.net application. One is *.aspx.cs and another is *.cs

The first one works as code behind file for a *.aspx file. For instance, the most common file you find in any application is default.aspx & default.aspx.cs

Default.aspx file contains all the UI (HTML) which you want to show the user and Default.aspx.cs file contains code to manipulate the content in the aspx file. You can have a Label control in aspx file to display logged in user name & you will write code in aspx.cs file to set the logged in user name in that Label control.

*.cs files are mainly class files created by developers to write extra logic for the functionality. For example, you can create a helper.cs class and write code for return the name of the logged in user. You can then call this function from the default.aspx.cs file to display the logged in user name. The benefit of creating the class file in this case is that it can be reused on any page, i.e. you can display the logged in user name in any aspx page by calling this class function from the aspx.cs file.

Generally adding an aspx file to the project adds an aspx.cs file automatically. For *.cs file, you will need to first select additem and then select class file from the list of file types.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900