May 09

Getting started with dynamic data pages and controls

Posted in ASP.NET      Comments Off on Getting started with dynamic data pages and controls

[After talking with my friend JPC, I think I should change the title of these posts After all, aspx pages are DYNAMIC pages!]

The ASP.NET May Futures introduces several goodies. One of those goodies is dynamic controls. With them, you can build data bound pages really fast which is good if you”re still doing that kind of stuff (I”m not, at least not in 98% of the projects I”ve been envolved with. However, after running some tests, these features seem like a good way of getting data really fast, so hy not spend some time looking at it? – and I”ve heard that they”re going to give us some kind of support for our business objects – at least, that”s what i”m hoping for!)

Lets start from the beginning. To enable these controls, you need add a couple of dlls to your bin folder and add some entries to the web.config file. The easiest way to get these features is to create a new Dynamic web site.

Doing that results in a couple of additions to the web.config file. First, you”ll see several dlls added to the <assemblies> section:

  <add assembly=”System.Core, Version=,Culture=neutral,
  <add assembly=”System.Web.Extensions, Version=, Culture=neutral,
  <add assembly=”Microsoft.Scripting, Version=, Culture=neutral,
  <add assembly=”Microsoft.Scripting.Vestigial, Version=, Culture=neutral,
  <add assembly=”IronPython, Version=, Culture=neutral,
  <add assembly=”IronPython.Modules, Version=, Culture=neutral,
  <add assembly=”Microsoft.JScript.Runtime, Version=, Culture=neutral, 
  <add assembly=”Microsoft.JScript.Compiler, Version=, Culture=neutral,
  <add assembly=”Microsoft.Web.Scripting, Version=, Culture=neutral, 
  <add assembly=”Microsoft.Web.DynamicDataControls, Version=, Culture=neutral,

The assemblies marked on bold are very important for getting the correct behavior from this type of pages. The <pages> section is also modified:

<pages compilationMode=”Auto”
      <add tagPrefix=”asp” namespace=”Microsoft.Web.DynamicDataControls”
                   assembly=”Microsoft.Web.DynamicDataControls” />
      <add tagPrefix=”asp” namespace=”System.Web.UI” 
                   assembly=”System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35″/>

Now, there are a lot of interesting things going on here! For starters, take a look at the pageParserFilter type attribute. It”s a new attribute that has been introduced in ASP.NET 2.0 and that I recall having seen around, though I”ve never tried to get more info till now. After some googling, I”ve got my hands on this pearl! (nop, i”m not talking about the programming language 🙂 ). If you read it, you”ll see that dynamic pages are based on the “no-compile pages” concept that which already exists on ASP.NET 2.0. The cool part about dynamic pages is that the no-code existing restriction in the page is gone! Yes, shocking, but true 🙂

How did they do that? well, it seems like they”ve managed to replace all the <%…%>, <%=…%>, <%#…%>, event handlers (ex.: onClick=”something”) and server script blocks (<script runat=”server”) with custom controls that are capable of rendering themselves on the page. This is really really cool! If like me you enjoy digging into these things, then fire up reflector and take a look at the ProcessCodeConstruct method. what can i say? pure genius!

Another difference (when compared with the ASP.NET traditional web app) is the base class of your pages: now you”re using a new class, DynamicDataPage. Notice also how the userControlBaseType attribute is pointing to a new class introduced by the new future dlls. Both of these attributes define the base classes for pages and controls (when you don”t specify it). Unfortunately, i still didn”t manage to get the time to go over these classes :(.

The web.config file also adds a new module: DynamicLanguageHttpModule. The previous doc says that this module is used to create a global.asax clone that is consumed by these new kind of applications. Again, no time to get info on the internals of this class. And guess what: there are also new handlers! Yep,  aspx pages requests are now handled ny the DynamicDataPageHandlerFactory, which basically will do the “correct” thing when it receives a request (more on this when we look at building dynamic pages!).  btw, there”s another new handler (AutoHandler) which I”ll also leave for another post.

To end the post, I must mention new dynamicDataControls section, which will let you specify some options regarding the mapping of the data tables on your pages (again, more on this on future posts!)

it seems like MIX has really given us lots of cool stuff this year 🙂 thank you guys!