Debugging JavaScript in Visual Studio
 
Published: 19 Dec 2006
Abstract
In order that all the inputs are validated before submitting the same to server, client side validation is required. Most browsers support JavaScript, which is well-suited to this purpose.
by Rajendra Kumar Sahu
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 24525/ 30

Introduction:

There is no denial of the fact that web applications are more scalable then its counterpart desktop application. If we call upon the past couple of decades and compare the present scenario from the standpoint of application software, undoubtedly web applications have gained popularity over desktop applications. The architecture of a web application is different than that of desktop applications. Web pages typically are composed of some html tags, images, scripting tags and JavaScript. Web pages interact with web servers with specific requests to execute web pages hosted on the web servers using browsers. There are various web servers that are in use these days. The most popular are IIS, WebSphere, Weblogic, Apache, etc. Web servers are installed with script engines. Such scripting engines are basically collections of libraries (dlls). When a page is requested from a browser the web server does not convert html tags, but interprets and parses all server tags and returns html as an output back to the browser.

Web pages have become more and more interactive these days and often collect some input from the user and send that input to the server for interpretation. Increasingly, it is the onus of the developer to validate each and every such input on a web page. Validation of web pages has become sine-qua-non. If the developer does not validate inputs, the request becomes erroneous and the web application might throw an exception or even crash at some point. In order to ensure the inputs are validated before submitting the same to server, client side validation is required. There are some popular scripts that are used for client side validation. JavaScript and VBScript are two of these. Most browsers these days support JavaScript. Had there been no such scripts for web form validations then the web developers would be in a state of quandary. Now this is an era where users prefer doing most of their work on the client side, then to shuttling it to the server as needed.

This kind of technology is in the transition of creating its potential presence. It is not AJAX (Asynchronous Java and XML). I had an occasion to make some spade work in AJAX and I came up with one sample application. It is really great and different too. In AJAX there is no escape from using less JavaScript. The developer had to shift most of the logic required for the web form and write JavaScript as a consequence of which the script size in terms of line numbers increases and so also become arduous to debug and fix errors. Microsoft’s Visual Studio IDE lets developers write code with ease. The debugging has become quite simple and easy which was not possible in traditional ASP application. In spite of the latest and new features in VS IDE, some of us find it cumbersome to debug JavaScript. But now you can stretch your legs and unfold you arms for debugging with JavaScript. There is a way out to debug JavaScript too. A question might be whirling in your mind as to how to do that. Here are the some useful tips to debug JavaScript in asp.net.

Steps to be followed to debug JavaScript on asp.net: In this article I have used IIS and Visual Studio 2005.

Configurations:

Step 1:

Open an existing asp.net application in Visual Studio 2003/05 if there is any, which uses JavaScript or create a new demo application from scratch.

Step 2:

When we create a web project in Microsoft’s Visual Studio a file in the name of web.config is created by default in the web project.

We need to check the following setting:

<compilation debug="false" strict="false" explicit="true" />

Then change the debug setting to “true” as in the following.

<compilation debug="true" strict="false" explicit="true" />

Step 3:

Open Internet Information Service (IIS). Here is how to open IIS.

Start à Settings à Control Panel à Administrative Tools à Internet Information Services

à Expand Web Sites à Default Web Site à right click on your web project you want to debug and click properties à click Directory Tab à click configuration à in the new opened window click Tab Debugging and if two check boxes labeled “Enable Server Side Script Debugging” and “Enable Client Side Script Debugging” are unchecked then check those two check boxes. (Pl refer to Screen Shot 1)

Figure 1

                                   

 

Step 4:

Open the Internet Explorer browser, click on menu Tools à Internet Options à Advanced Tab à if Disable Script Debugging (Internet Explorer) and Disable Script Debugging (Other) check boxes are checked then uncheck those two check boxes and click button OK. (Refer Screen Shot 2)

Figure 2

Step 5:

Now, open your web project in Visual Studio IDE. Select menu Tools.

If you open the project in VS 2003 then under Tools menu select attach a process and select aspnet process and attach the process to the application.

If you open the project in VS 2005 then it does not require you to explicitly attach the aspnet process. In the JavaScript add a break point where you want to debug and also add a break point in the .vb or .cs code file where the JavaScript function is called.

Step 6:

Run the project by clicking on icon Start. The application will start and wait at the break point where you placed the break point. 

Conclusion

Download Sample

Isn’t it pretty simple to debug JavaScript?!

Author - Rajendra Kumar Sahu

www.mindfiresolutions.com

 



User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-24 8:08:32 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search