Moving ASP.NET Designer Generated Code to Separate Designer.vb File

Introduction

If you’ve converted an an ASP.NET application from versions of Visual Studio 2003 and earlier to 2005 and beyond, you’ll notice the converted web pages behave slightly differently than those natively generated in new projects. The difference is that designer generated code used to have to live inline with developer code because all class properties needed to exist within the same file.

Solution

Starting in .NET 2.0, the compiler can now use the partial keyword which allows you to split up the declaration of a class over n number of files. The paved the way for Visual Studio to break apart the ugly code it generates from the (hopefully) beautiful code you’ve written. To make use of this feature on old asp.net web applications that have been converted to a compatible version of visual studio, simply do the following two steps.

5 Easy Steps

  1. Take the entire region label Web Form Designer Generated Code and Delete it from your code behind file:

  2. Our Solution Explorer currently looks likes this:

  3. Right Click on the .aspx or .ascx page and Select Convert to Web Application

  4. It will add a designer file with all the code we just deleted:

  5. Of course, if you turn of “Show All Files”, you’ll still only see the page in your solution explorer

And that’s it! Now enjoy the faster design time analysis and cleaner code that comes from separating your generated code and your written code.

7 comments:

  1. The workflow was seamless despite occurring between states. They were communicative and attentive to detail.
    top web design firms

    ReplyDelete
  2. They communicated effectively and delivered on-time.
    UX agencies

    ReplyDelete
  3. The people are very lucky to have this blog because it has better knowledge.
    design agencies SF

    ReplyDelete
  4. It’s amazing to visit again n again coming to your blogs the superb effort is here.
    best product design companies

    ReplyDelete
  5. Moving ASP.NET designer-generated code requires careful consideration. Can You Use Relocating files or elements can break the application if not handled correctly.

    ReplyDelete