Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

Trace.Warn not working in my class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tshad - 27 Sep 2007 20:43 GMT
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
Mark Fitzpatrick - 27 Sep 2007 20:53 GMT
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.

Signature

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

>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
[quoted text clipped - 49 lines]
>
> Tom
tshad - 28 Sep 2007 03:57 GMT
> 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

>>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
[quoted text clipped - 49 lines]
>>
>> Tom

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.