Exploring the depths and potentials of ASP.NET RSS 2.0 or Subscribe to .BenRush by Email
 Wednesday, July 18, 2007

Please Note: You must enable Script Debugging in Internet Explorer in order to follow what you are about to see here. Please do this!

Also.....Beta-1 warning here - things will change.

I find it very interesting to watch how our development environments have changed over the past few years; I remember a long, long time ago writing an entry about doing debugging of javascript in Visual Studio 2003. In any case, I really think I would like to walk everyone here through doing this in the new Visual Studio 9.

One of the coolest parts of Visual Studio 9 is the intellisense feature that you get with JavaScript. Therefore, let's do some intellisense and script debugging of ASP.NET AJAX client code through the new Visual Studio 9. To start, I create a new web solution in VS 9 and add a reference to System.Web.Extensions (for ASP.NET AJAX). I then want to add my ScriptManager control to the page, followed by a HTML button that I will execute some custom ASP.NET AJAX client script on a HTML textbox. The end result looks like this:


Next, I hook up an event handler in JavaScript with the button by double clicking it and getting presented with a method body:





In the spirit of ASP.NET AJAX being "asynchronous" I will then code into it a WebRequest class that will make an asynchronous call to any URL that is placed within the textbox. As you can see below, I have full intellisense making the use of the Sys.Net.WebRequest class a breeze:



I will then complete my use of the WebRequest class. I run into a bug, however - some null reference exception in my nicely formatted, intellisensified code. The code looks alright from the outside, it looks like this:




...but yet in the browser I get an error whenever I try to click the button, regardless of what I have in the textbox. So, let's set a debug break point on the text I'm about to pass into the set_url method and see what happens:




It says requestURI is null. So, I must have screwed up somewhere in my code?!? So, I look back on my code and realize I'm using the 'nodeValue' property instead of the 'value' property. A quick change of the code and I now get the following:




Slick, huh? Oh, and please note that even though I'm using "cnn.com" here, you won't be able to unless you are actually hosted on cnn.com. To prevent malicious scripting, you can only cause an asynchronous request to your own domain through ASP.NET AJAX.

kick it on DotNetKicks.com
Wednesday, July 18, 2007 4:22:04 PM (Central Standard Time, UTC-06:00)  #    Comments [2] - Trackback
AJAX | ASP.Net | Visual Studio

Computers Blogs - Blog Top Sites

Archive
<January 2009>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009
Benjamin Rush
Sign In
Statistics
Total Posts: 444
This Year: 0
This Month: 0
This Week: 0
Comments: 128
Themes
Pick a theme:
All Content © 2009, Benjamin Rush
DasBlog theme 'Business' created by Christoph De Baene (delarou)