Utility class or Common class in asp.net

2.9k views Asked by At

Do anyone knows about the class which has the common function which we generally use while developing web application. I have no idea what you may call it, it may be the utility class or common function class. Just for reference, this class can have some common function like:

  1. Generate Random number
  2. Get the file path
  3. Get the concatinated string
  4. To check the string null or empty
  5. Find controls

The idea is to have the collection of function which we generally use while developing asp.net application.

3

There are 3 answers

0
Mormegil On

No idea what you are really asking, but there already are ready-made methods for the tasks you write in various library classes:

  1. Random.Next() or RNGCryptoServiceProvider.GetBytes()
  2. Path.GetDirectoryName()
  3. String.Concat() or simply x + y
  4. String.IsNullOrEmpty()
  5. Control.FindControl()
0
Dave M On

Gotta love the intarwebs - An endless stream of people eager to criticize your style while completely failing to address the obvious "toy" question. ;)

Chris, you want to inherit all your individual page classes from a common base class, which itself inherits from Page. That will let you put all your shared functionality in a single place, without needing to duplicate it in every page.

0
Marek Kwiendacz On

In your example it looks like utility class - it is set of static functions.
But I think that you should group it in few different classes rather than put all methods in one class - you shouldn't mix UI functions(6) with string functions(3,4), IO functions (2) and math(1).
As Mormegil said - those functions exists in framework, but if you want to create your own implementations then I think that for part of your function the best solution is to create extension method.