SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to debug a method and need to trace how a variable is being changed to see where I went wrong. What in ASP.NET/C# could I use to do this?

For example if it was php I could stick an echo where ever I need to check the value and it would print it to the html. JavaScript I could use alert(var);

share|improve this question
Can't you use normal debug in Visual Studio? Set a breakpoint in left margin and hit F5. You could also use SPLog (… ) and keep an eye on ULS. – eirikb Sep 6 '12 at 20:16
up vote 1 down vote accepted

When on a developing machine set a break point and simply use the debug option of Visual Studio. Enable "Tracing" might also be a valuable topic to read into.

If not on a developing machine. Consider into using a logging framework. There are several free frameworks available in .NET that are highly configurable.

When in a SharePoint context consider logging errors to the ULS or the event viewer.

share|improve this answer

I usually just write the value to a label on the page.


<asp:Label ID="test" runat="server" />


test.Text = myVar.ToString();


test.Text = "myVar: " + myVar.ToString();
share|improve this answer
This works well for our team on smaller projects as well. – Aaron Sep 7 '12 at 14:14
I only use this in situations where I can't use the VS debugger, but it's quick and easy. Used to do this a lot more with classic ASP apps... – RJ Cuthbertson Sep 7 '12 at 15:12
Yes, we use it in situations where we are testing on a server without VS installed (Test, Prod) and setting up a custom logging solution is more hassle than it's worth. – Aaron Sep 7 '12 at 15:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.