ASP.NET C# Create a class / function that can be used among all pages

Posted on 2011-02-14
Last Modified: 2012-05-11
How to create a class / function that can be used among all pages?

should I create a class page and add my function there?

Thank you!
Question by:mawingho
LVL 12

Accepted Solution

Mamtha1982 earned 167 total points
ID: 34894251
Yes you can do...

Add New Item -> Class

Than add you functions as "public". if you want call this function without creating object, make it as "static"


Author Comment

ID: 34894253
i tried to do that...
and i wanna set the session variable
but it does not allow me to do that...
LVL 20

Assisted Solution

informaniac earned 333 total points
ID: 34894256
The class has 2 b static. Or u can create a class tht inherits frm Page class & have all ur .cs files inherit frm this
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

LVL 20

Assisted Solution

informaniac earned 333 total points
ID: 34894280
U need to add a reference of System.Web & use HttpContext.Current.Session["myVar"]=val;

Author Comment

ID: 34894282
hot it thanks

Author Closing Comment

ID: 34894283
LVL 39

Expert Comment

by:Pratima Pharande
ID: 34894287

Imports System.Web.UI.Page

will allow you to use sesions in the page

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question