Jan Schreuder on .Net

.Net code samples, experiences, observations

View my professional profile on LinkedIn

Recent Posts

Tags

News

  • Inappropriate comments will be deleted at my discretion.

    The information and code samples in this weblog is provided "AS IS" without warranty of any kind, either expressed or implied, including but not limited to the merchantability and/or fitness for a particular purpose.

Community

Email Notifications

Tool suppliers

Tools

General

Microsoft

Favorite blogs

Archives

How to - Create a missing designer.cs file

I was running into this just now and found a quick way to solve it, so I just posted it for future reference.

I have an ASP.Net web application project in .Net 2.0 which was migrated from .Net 1.1 some time ago. I noticed that a few aspx pages did not have a designer.cs file. All controls on those pages were listed as protected variable in the main code behind page, like this example:

/// <summary>
/// An example label
/// </summary>
protected System.Web.UI.WebControls.Label Label2;

And it annoyed me. It was not consistent with the new pages in the application, and most other aspx pages that were also there during migration did have the designer.cs file. So how to solve this, in order to get a more consistent use of ASP.Net. I followed the following steps to do this:

  1. First step - Make sure the latest version of the project is on your machine.
  2. Second step is to remove the protected variables for the controls from the normal code behind cs file.
  3. Now right-Click on the project and select 'Convert to Web Application'

The missing designer.cs is now created and added to the project. The protected variables, which were removed from the main code behind class are now in the partial class in the newly created designer.cs. The class in the original code behind class is also changed to a partial class.

If you forget step 2 and still want to remove the protected variables from your code behind class, then follow the following steps:

  1. Remove the protected variables for the controls from the normal code behind cs file.
  2. Open the ASPX file and make sure you view it in Source (HTML) mode
  3. Select the entire HTML mark up using CTRL-A
  4. Now press CTRL-K followed by CTRL-F

The HTML mark-up will be re-aligned and the designer.cs file will be recreated, including all the protected variables.

Comments

matthew said:

Jan, for your second scenario you could do the following:

1. Remove the protected variables for the controls from the normal code behind cs file.

2. Delete the designer.cs file

3. Right-click on the aspx file, and select Convert to Web Application.

This technique also works for the dreaded "Unable to connect to undo manager of source file...".

# October 17, 2008 4:55 PM

Sudonim said:

Many thanks.  just started getting that error after editing a fiddely page in (which has been upgraded from .Net1.1 )in VS 2008 - the protected / delete designer.cs and convert to web app solved it for me!

Thanks for taking the time to put this solution up there...

i suggest you go:

connect.microsoft.com/.../ViewFeedback.aspx

and let them know the solution :)

# March 26, 2009 12:09 PM

Richard said:

Brilliant, work around. Saved me a lot of time.

# December 30, 2009 11:19 PM

hidha said:

Thanks very much for the tip.

# March 25, 2010 7:40 AM

Great tip said:

great tip it took me a while to find a decent solution but this is it

thank you

# May 20, 2010 9:08 PM

dotnetguts said:

That was good tip, but i figured out easy way to fix this problem.  <a href="dotnetguts.blogspot.com/.../label-does-not-exist-in-current-context.html">Check out solution</a>

# June 2, 2010 1:17 PM

Bryan said:

If this Happens on C# Win Forms?? how can we correct the same?

# October 20, 2010 3:40 PM

Amol said:

thank u very much that helped me.

# October 11, 2011 8:17 AM

Himanshu said:

It worked.. thx very much...

# June 2, 2012 11:32 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Please add 8 and 8 and type the answer here: