How to call .cs file from .aspx.cs file in asp.net c#?

Today in Engineer's World, we are discussing a C# query faced by a developer in very easy way. Posted By- +Manish Kumar Gautam +LIVE VIAR  +ASP.NET SOLUTIONS

Click imagination hunt to see latest Blogs


Calling .cs (class file) from .aspx.cs (webform code behind file) in Asp.net C#

This question is very general. And is faced by almost everyone including me. So, I have tried something which will be very helpful to everyone and beginners.

To understand this let's create a new website.



Select Asp.net Empty website. After writing the file name click OK button.



Right Click on the website title in the Solution Explorer -> Add -> Choose Web Form (or Add New Item) -> Write the appropriate web form name and click OK button.







Similarly, to add a class file. Right click on project title -> Add new item.



Choose Class file. Write the file name and click the Add button.



An alert box will appear, that will ask that all the class file will be added in 'App_Code' folder. Click 'Yes' button. It is not necessary; you can add your own folder. But, it's good to keep all your class file in 'App_Code' as it will keep your files well organized and easily managed.



You can see that only your class file is added in the 'App_Code' folder.




Related Questions:

Q-1 Why class files need to add in 'App_Code' folder?
Ans. Files need to be add in 'App_Code' folder because:
A) It not only store class file, but it can also store various other the files, such as typed data set, text files, and reports. And it will automatically compile at run-time.
B) Files can be easily accessible through the project.
C) One of the important features of the App_Code folder is that only one .dll is created for the complete folder, irrespective of how many files it contains when we publish our project.

Q-2 Can we access a class file that is declared in the 'App_Code' within our entire application?
Ans. Yes. Files declared can be easily accessible through the project.

Click imagination hunt to see latest Blogs

Keep learning and sharing...

Comments

Popular posts from this blog

SSC CGL 2016 Tier-1 Marks / Result

DATA TYPES IN C#

Pattern printing program

IS STRING MUTABLE OR IMMUTABLE IN .NET?

Top Mutual Funds

SSC CGL 2017 TIER 2 RESULT OUT

JUST IN TIME (JIT)

Can we have multiple Main methods in one class

TOP 15 VISUAL STUDIO SHORTCUT KEYS

Top 10 Interview Tips and Questions