Posts

Showing posts from August, 2008

Easy TraceLogging In C#

The .NET Framework includes some convenient ways for tracing and debugging. In this post, I'll discuss how to easily add tracing functionality to your apps to output data to a text file. First, define a trace switch in your App.config file. This should be placed in the system.diagnostics node, and the point of the switch is to specify the level at which to output data with the switch. Here's an example: <system.diagnostics>   <!--   TRACE SWITCH VALUES   0 = Off   1 = Error   2 = Warning   3 = Info   4 = Verbose   -->   <switches>     <add name="MainTraceSwitch" value="4"/>   </switches> </system.diagnostics> There are five possible values: 0 = Off 1 = Error 2 = Warning 3 = Info 4 = Verbose So, if you set the value of your switch to 1, you're telling it that you only want to trace on errors. If you set it to 4, you're telling it to trace everything. Basically, you'll check this value in your code before you wr

How to Update an UpdatePanel Using JavaScript from an IFrame in ASP.NET

I recently had to make some additions to a website I was working on which involved the addition of an AJAX UpdatePanel which would contain a GridView. The GridView would contain rows with information related to submissions we received by the user. A timer would ensure that the GridView would be updated in a timely fashion and reflect any updates in our database, but we also wanted to instantaneously update the GridView as soon as a new submission was received. Updating an UpdatePanel from JavaScript wasn't a problem, but the source of new submissions to the site was located within an IFRAME hosted on the page, not on the page itself. How could I update the UpdatePanel on the main page when the page inside the IFRAME was submitted? Turns out, it's no big deal. All you need to do is add code to the onload event of the IFRAME. This code will call the __doPostBack() JavaScript function that ASP.NET renders when you use the AJAX components. This function takes two parameter