I am new to ASP.NET C#. I try to follow this tutorial page to make a function using globally, but no luck. https://web.archive.org/web/20210612122420/http://aspnet.4guysfromrolla.com/articles/122403-1.aspx
What I try to do is use a function global any where in my code. I have a function called "FormatDateNoTime". I have create a Class file under App_Code folder. But when I call that function in one of my code behind page (example Page1.aspx.cs), it gives me the error:
Error: The name 'MyClass' does not exist in the current context
MyClass.cs file under the App_Code folder.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for Class1
/// </summary>
public class MyClass
{
//
// TODO: Add constructor logic here
//
public static string FormatDateNoTime(string input) {
string thedate;
DateTime strDate = DateTime.Parse(input);
thedate = strDate.ToString("MM/dd/yyyy");
return thedate;
}
}
The code in my Page1.aspx.cs calling the FormateNoTime function
TextBox BeginDate = (TextBox)FormView1.FindControl("BeginDate");
BeginDate.Text = MyClass.FormatDateNoTime(objDs.Tables[0].Rows[0]["BeginDate"].ToString());
It seems like other pages don't recognize this class.function().
Please help. Thanks in advance.
objectandEventArgsparameters?? They are meant for event handlers..