Trace.Warn not working in my class

T

tshad

I have a page with Trace.Warns statements in my Page_Load and functions that
it calls, but it doesn't seem to work in a class that is defined on the same
page. I am writing this in C#

I am getting the following error at the 1st Trace.Warn:

***********************************************
Compiler Error Message: CS0118: 'System.Web.UI.Page.Trace' denotes a
'property' where a 'class' was expected

Source Error:

Line 84: {
Line 85: decimal mTemp = (decimal)dAmount;
Line 86: Trace.Warn("before rounding mTemp = ");
Line 87: mTemp = Decimal.Round(mTemp,2);
Line 88: Trace.Warn("after rounding mTemp = " + mTemp + " dBalance = "
+ dBalance);
**************************************************************************

The Function is:
*************************************
// Deposit - any positive deposit is allowed
public void Deposit(double dAmount)
{
if (dAmount > 0.0)
{
decimal mTemp = (decimal)dAmount;
Trace.Warn("before rounding mTemp = ");
mTemp = Decimal.Round(mTemp,2);
Trace.Warn("after rounding mTemp = " + mTemp + " dBalance = " +
dBalance);
dBalance += (double)mTemp;
}
}
****************************************

But in my function (not part of the class other than the Page class) the
Trace works fine:
**************************************************
void OpenBankAccount()
{
// open a bank account
Trace.Warn("Create a bank account object");
BankAccount ba = new BankAccount();
ba.InitBankAccount();
*****************************************************

Why wouldn't it work in a class defined on the same page?

Thanks,

Tom
 
M

Mark Fitzpatrick

Does the class you have inherit from the page object?

You can always use HttpContext.Current.Trace.Warn, which is the real method
call and not the shortcut that pages derived from the System.Web.UI.Page
provide.
 
T

tshad

Mark Fitzpatrick said:
Does the class you have inherit from the page object?

You can always use HttpContext.Current.Trace.Warn, which is the real
method call and not the shortcut that pages derived from the
System.Web.UI.Page provide.

That was it.

I thought like all my other code when I don't use code-behind (Dreamweaver),
I can access functions such as Trace. I normally don't have to explicitly
define HttpContect.Current in my pages.

Thanks,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top