B
Bennett Haselton
I've noticed that if you enter the following code in the codebehind
page for an .aspx page, it won't compile because the call to
Trace.Write() is not valid except in methods of a class derived from
System.Web.UI.Page. Two questions:
1) I don't know much about C# but I was under the impression that if
certain classes and functions were available in a namespace (as the
result of a "using" statement at the top of a file), then they were
available throughout the namespace. If Trace.Write() is available as
the result of one of the "using" statements at the top of the
codebehind file, then how is it not available in the MyClass class?
And if Trace.Write() is not imported by any of the "using" statements,
then how is it available to the WebForm1 class?
2) In that case, is there any way to call Trace.Write() statements
from classes other than the page class, to aid in debugging? I added
"using System.Diagnostics;" to the beginning of the code so that I
could call Trace.Write() from the "MyClass" class, but the output
still didn't show up in the trace.
-Bennett
Here's the code:
*****
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace tracetest
{
public class MyClass
{
public MyClass()
{
Trace.Write("MyCategory", "MyMessage");
}
}
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
Trace.Write("MyCategory", "MyMessage");
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web
// Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
page for an .aspx page, it won't compile because the call to
Trace.Write() is not valid except in methods of a class derived from
System.Web.UI.Page. Two questions:
1) I don't know much about C# but I was under the impression that if
certain classes and functions were available in a namespace (as the
result of a "using" statement at the top of a file), then they were
available throughout the namespace. If Trace.Write() is available as
the result of one of the "using" statements at the top of the
codebehind file, then how is it not available in the MyClass class?
And if Trace.Write() is not imported by any of the "using" statements,
then how is it available to the WebForm1 class?
2) In that case, is there any way to call Trace.Write() statements
from classes other than the page class, to aid in debugging? I added
"using System.Diagnostics;" to the beginning of the code so that I
could call Trace.Write() from the "MyClass" class, but the output
still didn't show up in the trace.
-Bennett
Here's the code:
*****
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace tracetest
{
public class MyClass
{
public MyClass()
{
Trace.Write("MyCategory", "MyMessage");
}
}
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
Trace.Write("MyCategory", "MyMessage");
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web
// Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}