views:

27

answers:

1

I have many existing scripts that I need to debug, all embededed from code behind.

I would prefer to use Visual Studio 2008 client side debbging features, but breakpoints can only be set inside the aspx file withing a script block.

The problem is I can't put a breakpoint on the scripts because they are all registered from the code behind file(not the aspx file). The scripts are added to the page using ClientScriptManager.RegisterClientScriptBlock Method (Type, String, String, Boolean)

Here is an example(it's not broke, just an example of how it's added to the page).

if (!cs.IsClientScriptBlockRegistered(cstype, csname2))
{
  StringBuilder cstext2 = new StringBuilder();
  cstext2.Append("<script type=\"text/javascript\"> function DoClick() {");
  cstext2.Append("Form1.Message.value='Text from client script.'} </");
  cstext2.Append("script>");
  cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), false);
}

Is it possible to debug it without having to pull out each script in a test page?

Edit: thank you

+2  A: 

Hi,

You should add the debugger; directive in your code. Something like this:

 cstext2.Append("<script type=\"text/javascript\"> function DoClick() {debugger;");
 cstext2.Append("Form1.Message.value='Text from client script.'} </");
...

Also, you will have to adjust your IE as follows:

Tools->internet options->advanced. Make sure that “Disable Script Debugging (other)” and “Disable Script Debugging (Internet Explorer) are NOT checked.

Now, if the DoClick method is called, a special exception will be generated and IE will suggest you to run a new instance of VS where you will be able to debug the script.

I hope, this helps.

DevExpress Team
That might be exactly what I need to use visual studio debugging in this case, I will give a try tomorrow, thanks!
GenEric35
Confirmed, works very well. Just one quick thing that had me searching for a bit, once IE prompts you to start VS, I let it attach, then press continue to let it complete, then I refreshed my web page and Visual Studio opened the document, where it had paused directly on my line where I had the debugger; line. Thanks again
GenEric35