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?
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();
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Msg1.Text = Utils.Basic.ToFrobbedStrin