Posts

Showing posts from April, 2008

How to Call Web Service Methods Asynchronously From an ASP.NET Page Using the Event-Driven Method in ASP.NET 2.0 and Higher

If you wanted to call a web service method asynchronously from an ASP.NET page in ASP.NET 1.x, you had two options: you could either use thread-blocking, or a callback method. With thread-blocking, you had to be mindful of the affect on other threads, and if you were using a callback method, you had to take steps to make sure that the page load didn't complete before the callback method was executed. In ASP.NET 2.0 and above, however, you have another option, which uses an event to signal that the asynchronous call has completed. It's easy, and even better, the page load won't complete until the event occurs. Here's how to use this convenient functionality. First, add the Async attribute to the Page directive that will be making the web service call, and set it's value to true, as shown below. This will allow the page to process asynchronously. <%@ Page Language="C#" Async="true" AutoEventWireup="true" CodeFile="Default.a

Troubleshooting the "'Sys' is Undefined" Error When Using AJAX Extensions for ASP.NET

If you've put together some ASP.NET code that uses some of the AJAX extensions, but the code doesn't work and you get a client script error that states "'Sys' is undefined", you're not alone. I've experienced this error myself, and none of the stuff I found on the web concerning the error helped me out any. But I was able to resolve the problem, and here's how: I added the following lines to the httpHandlers section of my web.config file. <remove verb="*" path="*.asmx"/> <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicK

How to Use LINQ to Query a Collection of Objects in .NET 3.5

One of the cool new features in .NET 3.5 is LINQ , which stands for L anguage In tegrated Q uery. It allows you to use a syntax similar to SQL to query datasources, XML, and objects. In this posting, we will use a subset of LINQ called LINQ to Objects to query a collection of objects. Let's start with the class of object we'll be querying. For this example, we'll use a very simple class called Spaceship. Spaceship has two properties: Name, which is the name of the ship, and CrewCount, which is the number of crew members it has. It also overrides the ToString() method to return a string which gives the ship's name and crew count. Here's what the class looks like: (Shameless plug: the code samples in this post were formatted for HTML with my HTML Encoder program, which you can download here ) /// <summary> /// A class representing a spaceship /// </summary> class Spaceship {     private int miCrewCount;     private string msName;     /// <summar