Start learning with our library of video tutorials taught by experts. Get started
Viewed by members. in countries. members currently watching.
Thousands of businesses have used Microsoft ASP.NET to build professional, dynamic websites. In this course, web developer David Gassner demonstrates the tools needed to build and deploy a dynamic site using ASP.NET 3.5 or 4.5. Covering everything from installing and configuring Visual Web Developer 2008 or Visual Studio Express 2012 for Web and SQL Server Express to creating web form pages, this course is designed to give beginning and intermediate developers hands-on experience.
When working with programming, it's useful to be able to see what's going on inside the application at runtime. Visual Web Developer provides a powerful debugger and the .NET Framework itself provides additional tools, both of which allow you to see what's happening by either adding code to your page or creating what are known as break points. In this video, I'm going to describe the use of tracing. The ability to output information to the webpage at runtime. This is a feature of the .NET Framework rather than Visual Web Developer the tool. And so it's done completely with code.
I will start off with the file LoopingCSharp.aspx. In this file, there is already some code that's doing some looping with a For loop and a While loop. If you didn't do the previous exercise where this file was created, you can create a new file now using a For loop or a While loop. I'll save this file under a name. Selecting File > Save LoopingCSharp.aspx as and I'll name the new file Tracing.aspx.
The concept of tracing will be the same regardless of whether you are working C# or Visual Basic. So we'll only demonstrate it with the single file. In order to use the tracing capability you must turn it on first. You can do this either one page at a time or you can do it globally for your entire website in the web.config file. I am going to demonstrate turning on tracing for just one file. I'll go up to the top of the file, to the page declaration and I'll add an attribute Trace = true. By default the Tracing capability is turned off. Now I'll save and I'll run the page, selecting Debug > Start Without Debugging.
As the page starts up it displays the code and then at the bottom of the page, a whole bunch of information is dumped on to the screen. You can find out what's going on as the page is loaded, by looking not just at the messages but also at the time stamps, the numeric values. If for example, a page is a long time to load, you can trace and find out where the time lag is happening by comparing the numeric values. As you scroll down, you will see a lot of information including the timing, the tracing and you will see also see something called the control tree which shows you what kind of objects that are part of the page.
Down toward the bottom, you will see a listing of different variable types. I have described how to use variable types in other videos in the series. There is the Headers Collection which lets you see what kind of information is being sent from the browser to the server and lots more information. So that's how you turn tracing on. Now let's take a look at how you can use this feature and create your own custom messages. I'll close the browser and return to the page. I'll press Alt+ Shift+Enter to go to full screen and then I'm going to take out the While loop in this portion of the page. I only need the For loop to demonstrate this and within the For loop, I'll place the cursor after the call to the output function and I'll use this code, Trace.Write.
Trace is the name of a class that's always available to you. As you can see in the pop-up help, the Trace.Write function, we see it's a number of arguments. The only one that's really required in this context is the string. The first argument and I'm going to pass in a value which is the same as I'm passing to the output message, The value of counter is, and I'll append the value of the counter variable. So now I'll be writing to the trace section at the bottom of the page.
I'll save my changes and I'll run the page. When the page first loads I see the trace information for the initial load. Then I'll click the Run Code page and I'll see the value of the counter is 1 and 2 in the top section that output is being handled by my custom output function. But then if I scroll down, I'll see in the Trace section the same information. Notice that I see time stamps indicating how long it took to get from one phase of creating the file to the next phase. So once again, if you are having performance problems in a page, the Trace functionality is a great way of tracking down where the delay might be happening.
As I mentioned, you can also turn Tracing on for the entire website. You do this in the web.config file. I won't go through those steps here but if you do need to turn tracing on for the entire site for some reason, you can do it through a centralized mechanism.
Find answers to the most frequently asked questions about ASP.NET Essential Training.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.