Link to home
Start Free TrialLog in
Avatar of TabbedOut
TabbedOut

asked on

static classes in ASP.NET

I have a static class Utils that defines some extension methods (eg. on String).

How can I use this in my ASP.NET page?   I would like to be calling things like Label1.Text = helloWorld.ToFrobbedString()

I am a newbie at C#, VS, and ASP.NET, so I need instructions about how to make the utility class somehow available to my own customized page class.   How are methods in the Utils class accessed by my ASP.NET codebehind (instantiated) classes?  What are the namespace (Using?) and Visual Studio things I need to do to link?

Utils.cs
========================================================================
namespace Utils
{
  public static class Basics
  {
    public static string ToFrobbedString(this String str)
    {
      return str + "Frobbed";
    }
  }
}
 
 
WebForm11.aspx.cs
========================================================================
namespace Mine
{
  public partial class WebForm11 : System.Web.UI.Page
  {
    protected global::System.Web.UI.WebControls.Label Msg1;
 
    public void Button_Click(Object sender, EventArgs e)
    {
      Msg1.Text = Msg1.Text.ToFrobbedString();
    }
  }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of OMC2000
OMC2000
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VikramMullick
VikramMullick

use
Msg1.Text = Utils.Basic.ToFrobbedString("Test data");