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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With