Tuesday, October 23, 2007

Troubles debugging javascript with IIS 7 and asp.net

Seems like I'm always having problems debugging javascript on my development machine so today I decided to try and get to the bottom of the issue. (...well, that and I have nothing to do)

I've gone through all the usual recommendations on the web.... turn off "Disable javascript debugging" on IE; turn on script debugging in visual studio; turn on script debugging in IIS 7.0. All are required but still didnt seem to allow the debugger to break into the script.

As it turns out, my problem only showed when I used the Page.RegisterStartupScript method... loading my scripts via the code-behind. Reverting back to the original html include statements fixed everything. Not sure what was going on here... I did a little bit more investigation but nothing conclusive.

Before (Mainpage.cs):
public void OnInit()
{
string js = ReadResourceString("includescript.js");
ClientScript.RegisterStartupScript(typeof(Page), "UIScriptHelper", js);
}


After (Mainpage.aspx):
...
<head>
<script type="text/javascript" src="includescript.js"/>
/head>

No comments: