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

Posted on 2011-02-14
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 12

Accepted Solution

Praveen Kumar earned 668 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 1332 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 20

Assisted Solution

informaniac earned 1332 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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 …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

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