SIGN UP MEMBER LOGIN:    
ARTICLE

Debug Javascript in Visual Studio 2005

Posted by Gaurav Tomar Articles | Visual Studio .NET November 06, 2008
This article explains you how to debug script in VS2005 by using practical Google map example.
Reader Level:

I have a curiosity to know that how we use breakpoints for javascript in asp.net or debug a particular javascript. Few days back, I solve this problem and I want to share this with all of you.

Configure IE to enable script debugging


First of fall we have to make certain settings in which are given below:

Open your Internet Explorer and go to Tools > Internet options > Advance tab and in "Advance Tab" make sure that "Disable script debugging (Internet Explorer)" and "Disable script debugging (other)" both checkboxes are unchecked.

Now you are ready to debug your script, I will show you this by using an example in which I create a Google map with marker.

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
        <title>Default Map</title>

        <script
 src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAzzZziWgipvlrJKbG_y1t_RRtDDpfVZbOfyV8CEj3g67I7c36_RSz9kcDtHYdiZnyGrD-2fmH2VGylQ"
           
type="text/javascript"></script>

        <
script type="text/javascript">
function load() {

debugger; //Use debugger keyword to debug your script in visual studio 2005

if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);

 //--create the info tabs---
var infoTabs = [
new GInfoWindowTab("Name", "Gaurav"),
new GInfoWindowTab("Description","Software Developer, India")
];

 //---add the click event for the marker---
var marker = new GMarker(map.getCenter());
GEvent.addListener(marker, "click",function() {

 //---open the marker info tab---
marker.openInfoWindowTabsHtml(infoTabs);
});

 //---add the marker---
map.addOverlay(marker);

 //---add the marker IF WANT TO OPEN INFO AT PAGE LOAD---
marker.openInfoWindowTabsHtml(infoTabs);
}
}
        </script>
</
head

 <body onload="load()" onunload="GUnload()">
   
    <div id="map" style="width: 500px; height: 300px">
   
    </div>
        <
form id="form2" runat="server">
            <div>
            </
div>
    </
form>
</
body>
</
html>

Write the above mention code in your project and press F5 to debug your project, now you can see your default.aspx in debug mode as shown below:

1.jpg

Figure 1.

Now you can debug your script by simply pressing F10 and easily track error in your script. After that press F5 to run your project and you will see the below given output in your browser window:

2.jpg

Figure 2.

Hope this will helps you, enjoy !!!

 

Login to add your contents and source code to this article
share this article :
post comment
 

This is an Awesome article... Thanks for posting...

Posted by rajesh kallem Mar 25, 2010

Thanks buddy....it is fantastic.....keep sharing Happy coding... :)

Posted by Aditya Kumar Feb 02, 2009

Its a nce and informative one

Posted by mariyappa v Jan 03, 2009
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Team Foundation Server Hosting
Become a Sponsor