Encosia - ASP.NET, AJAX, jQuery, and more

Why do ASP.NET AJAX page methods have to be static?

AJAX, ASP.NET, OO By . Updated June 13, 2008

Image of a spark (static).Dozens of variations on the title of this post are some of the most common searches that bring people here to Encosia. Unfortunately, the search engines all point to a post that doesn’t answer the question. It’s also a frequent question raised on the ASP.NET message boards, typically without a satisfactory answer provided.

However, it is an important question, the answer to which is important to understand. So, in an attempt to fill in this gap for the searchers and perhaps preemptively help others, I want to proceed to answer it as thoroughly as possible without overly complicating the whole business.

In order to do this, we’ll have to take a brief tour of WebForms, including:

  • Understanding what the Page class is, and why we have it.
  • One specific thing that the Page class does for us.
  • How this is accomplished, behind the scenes.
  • What the static keyword entails, when used with a method.
  • Finally, why page methods must be static.

Click here to read the rest of this post »

Databinding Class Data

ASP.NET, OO By . Updated April 18, 2007

It took me a few minutes to figure this out and Google was surprisingly unhelpful so hopefully this will be useful to others.

When databinding objects, only properties are available. To my dismay, simply making class fields public isn’t enough. Even though the field is right there, publicly accessible, the databinder acts as if it’s not.

Click here to read the rest of this post »