This tutorial is the seventh part of the ASP.NET Web Site Debugging tutorial series. This tutorial will demonstrate how to use the Call Stack in Microsoft Visual Studio 2010 with ASP.NET 4.0 and C#.
We moved our web sites to Server Intellect and have found them to be incredibly professional. Their setup is very easy and we were up and running in no time.
Creating a Web Site
To demonstrate the call stack window we will need to create a simple website with a few methods in it. At this point in the tutorial I have created a new ASP.NET Empty Web Site and am ready to add in some content and C# code. To begin:
- Right click the project in your solution explorer.
- Select add new item...
- Select a web form.
- Name it 'Default.aspx'.
- Click add.
- Open Default.aspx up to design mode.
- Drag and drop a label onto the web form.
Next, we need to add some simple code to call a couple of methods so that we can evaluate the call stack. To do this, add the following code to the Default.aspx.cs code behind file:
public partial class _Default : System.Web.UI.Page |
If you're looking for a really good web host, try Server Intellect - we found the setup procedure and their control panel, very easy to adapt to and their IT team is awesome!
Using the Call Stack Window
Now that we have some code to work with, let's go ahead and debug it. First, we need to add in a breakpoint in the Page_Load event method at the line 'SetLabel1();'. Then, go ahead and load up the web site with debugging and:
- From the top menu select Debug -> Windows -> Call Stack to view the call stack.
- Notice that the call stack contains some information and displays the Page_Load event method's signature and line number. This is because it is currently the only call on our call stack.
- Hit F11 to step into our SetLabel1() method that we are currently at. Notice that SetLabel1() is added to the top of the call stack.
- Hit F11 twice to step into our SetLabel2() method. Notice that it is now added to the top of the stack.
- Hit F11 three more times to finish up our SetLabel2() method. Notice that it is removed from the call stack.
Need help with cloud hosting? Try Server Intellect. We used them for our cloud hosting services and we are very happy with the results!
The call stack allows us to evaluate the current method calls that have been initiated to get to a certain point in your code. This can be helpful when you have method calls that are extremely deep within your code. Furthermore, you can determine what data you want to have the call stack display by right clicking in the call stack window and selecting different paremeters.
No comments:
Post a Comment