This tutorial shows how we can create our own classes and use shared code between different pages on our website. C# version.

Visual Studio allows you to create classes in separate files to be used in multiple pages on your website.
Classes you create are stored in the App_Code folder and can be in any language you prefer. For this tutorial, we’ll create a sample class:

When called, the class can either store data or return data. We create a text box and a button to show how we can store data in a variable in a separate class, and then a label to show how we can retrieve that same data.

The ASPX page which is using the class function:

The code-behind should look something like this:

Download Source Files