Yow-Hann Lee - Software Happens

All things Computer Science, .NET & WWW

  Home  |   Contact  |   Syndication    |   Login
  132 Posts | 7 Stories | 38 Comments | 50 Trackbacks

News


Article Categories

Archives

Post Categories

About

I've been meaning to post the following but only got to it just now. For those that have started playing around with the ASP.NET 3.5 Extensions CTP, you will have no doubt come across being unable to access controls declared in aspx from code behind. This is a heads up for those wanting to start dabbling in the MVC framework.

When you create a new ASP.NET MVC web project, the pages don't have a designer.cs file. In a typical web project, this is still dandy since you can access the controls by ID in code behind; the designer files are simply abstracted. However, in the MVC web project, you will get compilation errors. Instead, you could access inline. ASP.NET runtime will generate your declared controls (peek in temp dirs of your loaded modules), which explains why you can access and manipulate the controls inline.

Naturally, you may not want to do this inline. To access your controls in code behind, simply right-click on your web project and select "Convert to Web Application". And Voila!

Courtesy of ScottGu

posted on Thursday, December 13, 2007 7:26 AM