Debugging JavaScript using VS.NET and IE 6.0

From http://www.code101.com/Code101/DisplayArticle.aspx?cid=67

Introduction

Asp.net has come a long way from Asp on many facets, especially debugging. If you have work with ASP.net for a while and go back to work on ASP you would miss a lot of feature and debugging is the most you miss. Visual studio.net is an awesome IDE tool, allows you to step through the your server code, stored procedure and JavaScript too - Did you know this?

There is a growing demand for highly scalable, reliable and rich user experience web application, JavaScript has a major role to play on the client side scripting to avoid post back and never the less to avoid view state moving back and forth the wire in ASP.net applications.

Lets dive in and see how to debug JavaScript

IE browser settings

This work only with Internet Explorer 6 and VS .NET The first thing to do is to get browser settings right. Open IE and select the following menus Tools | Internet Options | Advanced | Disable script debugging (uncheck)

cid67.1.jpg

Back to ASP.net application

Let us try out a quick sample. Open an Asp.net project Drop a HTML button on the web form and write a javascript to add two numbers and raise an alert message on the client.

<script language="javascript">
 function Sum()
  {
    var a=10;
    var b=20;
    var c=a+b;
    alert(c);
  }
</script>

<INPUT type="button" value="Button" οnclick="Sum()">

Now run your project and when you see you web page go to the design mode of visual studio and select Debug | Windows | Running Documents from the Debug menu. This opens up a Running documents explorer click on the JavaScript.aspx file and place the break point on the line of Javascript you want to debug.

cid67.2.jpg
From here are you could debug like any server code – use the “Locals Window” to see all the objects or Immediate window to change values of the variables

Debugging JavaScript in External files

ASP.net debugger also allows us to debug javascript present in the in external files. Move this Javascript Sum() function to a file named JScript1.js and refer the JScript1.js file in the webpage

<script language="javascript" src=/Code101Demo/JScript1.js>

Run the project and repeat the steps Debug | Windows | Running Documents from the Debug menu. In Running documents explorer now you would see two files JScript1.js and JavaScript.aspx. Double click on the JScript1.js and set the break point as shown in the screen shot.

cid67.3.jpg
This technique is very handy not only to debug but also to learn a lot about how the Validation controls and Smart Navigation works in ASP.net. For those who are new to ASP.net the above-mentioned functionality are implemented using JavaScript file WebUIValidation.js and SmartNavIE5.js

By default they are located in the \aspnet_client\system_web\1_0_3705_288This folder name 1_0_3705_288 represents the CLR version number so each version of CLR would have a different client JavaScript files.

Debugger key word

Instead of manually setting the break point we could use the bedugger key word on the line to break. This technique comes handy on the scripts that run when the form loads. Lets try it out on the previous code.

function Sum()
  {
    var a=10;
    var b=20;
    var c=a+b;
    debugger;
    alert(c);
  }
Conclusion

Debugging JavaScript is really a cool feature of VS.net this saves developer a lot of time and frustration when writing JavaScript. Beside this it gives you chance to peeking into the plumbing activities of client side validation controls.

转载于:https://www.cnblogs.com/xioxu/archive/2009/03/07/1406045.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值