AJAX call using an ASP.NET Page Method

We’ve already been through AJAX calls using simple web pages and HTTP Handlers. But there’s still more ways to request data from the server. Today we’ll take a look at how to do so using server methods.

ASP.NET allows you to define methods in the code-behind of an ASPX page. This is very helpful in situations where you want to expose some specific server side functionality such as data retrieval for a specific page. If you need to make the operation available to multiple different .aspx pages it’s a better idea to use a web service so your pages can share the functionality. We’ll see how to use web services in the next post.

Please note that page methods must be declared as static, meaning a page method is completely self-contained, and no page controls are accessible through the page method. For example, if you have a textbox on the web form, there is no way the page method can get or set its value. Consequently any changes with regards to the controls have no affect on the page method. It is stateless and it does not carry any of the view-state data typically carried around by an ASP.NET page.

Read the rest of this entry »

AJAX call using an ASP.NET HTTP Handler

We’ve already seen how to perform an AJAX call using just a simple ASP.NET web page. Now we’ll see how to do it with an HTTP handler instead of a web page.

But, what is an HTTP handler? Well, as its names suggests, it is an element that handles HTTP requests. Well, but that’s what an .aspx web page does, right? Sure, but in a lengthier, slower and resource-hungrier way. Regular web pages inherit from the System.Web.UI.Page class, which contains a lot of overhead and pre and post-processing in order to make it easier for the programmer to return HTML code to the client performing a request. In other words, the web page class has stuff to make it easier to develop a web page. It’s got some logic, doesn’t it?

Read the rest of this entry »

AJAX call using an ASP.NET web page

We already saw what an AJAX call is and the different types there are. Today we’re going to see how to perform an AJAX call using a regular web page at the server. The page will be the connection between the client’s web browser and the server. It will take care of performing the operations at the server (let it be some kind of processes or calculations, or just a regular database access).

I’ll be using jQuery in this example. jQuery is a superb Javascript framework, and is the one I use the most. If you don’t know what it is yet, then the first thing you should do is getting acquainted with it. This JavaScript framework has many convenient functions to make an AJAX call. These functions hide much of the complexity of an AJAX call: you can forget about the XMLHttpRequest object if you wish, and only worry about what to do with the data once you get it back from the server.

Read the rest of this entry »

Different ways to use AJAX in ASP.NET

Today’s web applications are unthinkable without AJAX techniques. These techniques provide an improved user experience, and tighten the gap between traditional desktop applications and web applications. This means that mastering AJAX technologies is a must for anyone who’s doing serious web application development. In this article I’ll explain the basics of AJAX, and I will show how to program some AJAX calls using ASP.NET technology.

Read the rest of this entry »

PHP or ASP.NET?

The other day a friend of mine was telling me he was going to start a new project. He wanted to develop a new web app from scratch, and was telling me he was going to use PHP. He did have experience with ASP.NET from some other projects, so I told him to use this technology. But he still preferred PHP. The reasons he gave me were:

  1. PHP is free. You do not have to pay to use it. With ASP.NET you need to pay a whole bunch of licenses.
  2. PHP runs faster than ASP.NET.
  3. PHP hosting is cheaper.
  4. Out there on the internet, you can see more PHP than ASP.NET applications.
  5. There’s more CMS on PHP than on ASP.NET.

Ok, he had his reasons, but I didn’t fully agree with him. So I discussed some of those ideas with him:

Read the rest of this entry »

Sluggish database view? Materialize it!

The other day we were having some slow database view at our project. It was the main view of the new module we were developing, and it was slowing down the whole application to an unacceptable point. It was a rather complex view and could not be optimized much more. So, what was the solution we adopted? We materialized the view.

Regular views store just the SQL script needed to retrieve the data, and every time they are consulted the stored SQL query is executed. However, materialized views not only store the script, but the retrieved records as well, making it much faster.

Read the rest of this entry »

Software design patterns (IV): behavioral patterns

We’ve already been through a brief introduction to design patterns, and a description of the most important creational design patterns and structural design patterns. In this article we’ll take a look at the last category of design patterns: behavioral patterns.

Behavioral design patterns are concerned with the relationships among communications using different objects. They identify common communication patterns and provide a well-known solution to implement this communication, offering a higher degree of flexibility.

The most used behavioral patterns are:

Read the rest of this entry »

Software design patterns (III): structural patterns

We already saw what design patterns are and took a look at creational patterns in earlier articles. Today we’ll deal with the second category: structural patterns.

These design patterns are all about class and object composition. Class-creation patterns use inheritance to compose interfaces, whilst object patterns define ways to compose objects to obtain new functionality. All of these patterns aim to ease the design by identifying a simple way to realize relationships between entities.

The most common structural patterns are:

Read the rest of this entry »

Software design patterns (II): creational patterns

In an earlier article we saw what design patterns are and how they can help us. Today we’re going to take a look at the first category: creational patterns.

Creational design patterns deal with class creation and instantiation, and how to use those instances. Basic class creation could result in design problems or added complexity to the design. These patterns solve these problems by controlling this object creation.

Some examples of creational design patterns:

Read the rest of this entry »

Software design patterns (I)

Design patterns are solutions to common software development problems, and aim to facilitate the development of a software project. A solution must have proven effectiveness and be highly reusable (can be applied to different design problems in different circumstances) to become a design pattern.

A pattern describes a problem that happens over and over again in our environment, and then explains the core of the solution to that particular problem. Since it is just a scheme of the solution, the application of this pattern is not literal: it requires adaptation. You could use the same pattern a thousand times, and never repeat the way you applied it.

Read the rest of this entry »