Forcing regeneration of the designer.cs file
Locked
-
Friday, August 24, 2007 4:10 PM
Hello:
Occassionally I update the ascx file and the new control, or a rename of a control's ID isn't reflected in the .designer.cs file. How do I force the IDE to regenerate this source code file?
Also various machines in the office generate comments for this code while other setups don't generate comments. Where is the setting for turning this on or off?
L-
Answers
-
Saturday, August 25, 2007 11:59 AMModerator
The designer works a little weird. I would say it is a bug but it doesn't behave the way it should but it is pretty easily to replicate. Check at http://connect.microsoft.com to see if it has been reported.
Whenever you modify the ASCX file it is suppose to update the designer.cs file. However this updating doesn't occur instantly. Instead it occurs when you later open the designer file. If you don't open the designer file then it won't get updated normally. If you set a property on the control it'll generate update the designer file as well. It is almost hit and miss when it'll update the designer file. Needless to say if you open the designer file and save it outside of saving the ASCX file then it can easily get out of sync. In the right circumstances it won't generate comments or even variables for the controls. Here are some scenarios I can replicate starting with a new ASCX file.
-
Correct Behavior
-
Add a new control to the ASCX file.
-
Open the designer file.
-
Save All files.
-
The designer file contains the comments and variable for the control.
-
-
Empty Designer File
-
Add a new control to the ASCX file.
-
Open the designer. Notice a variable w/ comments was added.
-
Close the designer. Say No to the save prompt.
-
Save all files.
-
Open the designer file and notice the variable is gone again. It appears that the IDE gets confused about the modify state of the designer and assumes it is not dirty.
-
-
Missing Controls
-
Add a new control to the ASCX file.
-
Save the file.
-
Open the designer file.
-
Switch to the ASCX file and add another control.
-
Save the ASCX file.
- Switch to the designer file.
-
Close w/o saving.
-
Open back up the ASCX and designer files.
-
The controls will be out of sync until the ASCX file is modified again.
-
-
Designer file w/o comments
-
I replicated this issue really easily but I don't remember how I did it.
-
As far as preventing the comments I don't think you can.
My recommendation is to avoid opening the designer file at all. In the few cases where you might open it be sure to always save changes even if you haven't made any. If ever in doubt then add and then remove a control from the ASCX file to regenerate the designer. It is almost always best to leave the designer file closed.
Michael Taylor - 8/25/07
-
All Replies
-
Saturday, August 25, 2007 11:59 AMModerator
The designer works a little weird. I would say it is a bug but it doesn't behave the way it should but it is pretty easily to replicate. Check at http://connect.microsoft.com to see if it has been reported.
Whenever you modify the ASCX file it is suppose to update the designer.cs file. However this updating doesn't occur instantly. Instead it occurs when you later open the designer file. If you don't open the designer file then it won't get updated normally. If you set a property on the control it'll generate update the designer file as well. It is almost hit and miss when it'll update the designer file. Needless to say if you open the designer file and save it outside of saving the ASCX file then it can easily get out of sync. In the right circumstances it won't generate comments or even variables for the controls. Here are some scenarios I can replicate starting with a new ASCX file.
-
Correct Behavior
-
Add a new control to the ASCX file.
-
Open the designer file.
-
Save All files.
-
The designer file contains the comments and variable for the control.
-
-
Empty Designer File
-
Add a new control to the ASCX file.
-
Open the designer. Notice a variable w/ comments was added.
-
Close the designer. Say No to the save prompt.
-
Save all files.
-
Open the designer file and notice the variable is gone again. It appears that the IDE gets confused about the modify state of the designer and assumes it is not dirty.
-
-
Missing Controls
-
Add a new control to the ASCX file.
-
Save the file.
-
Open the designer file.
-
Switch to the ASCX file and add another control.
-
Save the ASCX file.
- Switch to the designer file.
-
Close w/o saving.
-
Open back up the ASCX and designer files.
-
The controls will be out of sync until the ASCX file is modified again.
-
-
Designer file w/o comments
-
I replicated this issue really easily but I don't remember how I did it.
-
As far as preventing the comments I don't think you can.
My recommendation is to avoid opening the designer file at all. In the few cases where you might open it be sure to always save changes even if you haven't made any. If ever in doubt then add and then remove a control from the ASCX file to regenerate the designer. It is almost always best to leave the designer file closed.
Michael Taylor - 8/25/07
-
-
Tuesday, September 11, 2007 6:10 PM
I have had major issues in VS05 with a few pages where controls were not being recognized in the codefile, and also third-party DLL's were not being loaded (" the namespace... did not load any ... controls"). I could go back and forth with Design and Source views, but in one case had no aspx.designer.vb file at all. At no time did I edit the designer files. I thought it was a memory issue that the large third party controls were not being loaded. Eventually, I had larger pages work fine.
The one thing that forced the designer file to be populated was to create an empty one and explicitly add it to the project, then various back and forths w Designer and Save. However, the same problems of controls (labels, etc.) not being recognized in code (though they were in the designer.vb file) and of DLL's not loading persisted (with much teeth-grinding). The good news: starting over with a fresh file and adding in each ASPX element has worked.
The difference appears to be the use of <span> and possibly <div> elements. Here's a snippet:
<div>
<span style="font-family: Arial">
<asp:Label ID="lblHideJS" runat="server" color = white > </asp:Label>
Welcome: <b><asp:Label ID="lblName" runat="server" Text="User"></asp:Label></b>
<asp:Label ID="lblProxy" runat="server" Text="Proxy:" Visible = False></asp:Label>
<asp
ropDownList ID="ddlProxy" runat="server" Width="170px" Visible=false>
<asp:ListItem>[none]</asp:ListItem>
<asp:ListItem>Farrell, John</asp:ListItem>
<asp:ListItem>Stewart, Carol</asp:ListItem>
</asp
ropDownList>
<br />
<br /><p></p>Nothing unusual, right? Designer did not complain about end tags, or anything. I could supply the whole files if MS wanted to test it, but the bottom line is that this ostensibly Designer-compatible aspx file totally got Designer "wrapped around the axel" with these inexplicable errors. Instead of my beating my head against the wall, the wall was beating on me. My advise: watch out for span (and div?) usage!
- Rand W.
-
Wednesday, October 17, 2007 2:35 PMThe OP asked how to cause the designer to regenerate.
I too have this issue, and its driving me up the wall to spend 45 mins designing an extensive WUC only to find out that I have to add each of my fields by hand to the designer file. This issue happens to me rather consistantly on Vista with vs2k5 sp1.
I dont care if MS adds a menu option when you right click an ascx/aspx page that Regens the designer file, but this is ridiculous.
IS there a method for regenerating the designer.* files??? -
Wednesday, October 17, 2007 2:44 PMModerator
The file gets regenerated whenever a control is modified in the ASPX/ASCX page or during compilation. If you delete the original designer.cs file and then modify the ASPX/ASCX page then it should be regenerated. Note that if the designer file does not appear under the ASPX/ASCX page in SE then it probably won't work properly. Also note that you should rarely open the designer file directly. If the designer file is open in the IDE then it will cause problems.
Michael Taylor - 10/17/07
-
Friday, October 19, 2007 2:50 PM
A pain in the #@$$.
Delete the designer.cs page, right click on the aspx/ascx page and choose Convert to Web Application.- Proposed As Answer by ufosnowcat Tuesday, April 21, 2009 12:44 PM
-
Thursday, April 03, 2008 7:48 PM
"Delete the designer.cs page, right click on the aspx/ascx page and choose Convert to Web Application."
Now there is the solution I was looking for and it works! Just simple and to the point.
Thanks, John!
David
-
Monday, June 16, 2008 11:22 PM"Delete the designer.cs page, right click on the aspx/ascx page and choose Convert to Web Application."
That was the tip I needed to find my similar problem, too. It didn't SOLVE the problem, but it REVEALED it: upon the attempt to regenerate the designer.cs file, I got this error monologue:
Generation of designer file failed: Control btnUpdate conflicts with field BTNUPDATE of a different case. Declaring both fields will result in an ASP.NET error.
Turns out VisualStudio 2005 has an odd case insensitivity. I had various constant strings that I'm using to change button .Text depending on the state of the form. I changed those to start with BTN_ instead, and all was well. -
Tuesday, December 09, 2008 3:54 PM
If there are errors int the aspx markup the designer may fail to generate the code control members. So you should check that the aspx file does not contains errors, then use the "convert to web applictaion" command.
Hope this helps.
- Proposed As Answer by Chris Keeble Tuesday, September 22, 2009 2:49 PM
-
Friday, September 25, 2009 5:37 AM
The above workaround didn't work with me. i am not successful. but the following did.
1) Change into designer mode
2) make a change (just modify some text or something)
3) save the file.
the following link is the source of this workaround.
http://blogs.blackmarble.co.uk/blogs/msteeples/archive/2009/05/20/visual-studio-does-not-update-the-asp-net-designer-cs-file.aspx
hope this helps.- Proposed As Answer by MarlonBohol Friday, September 25, 2009 9:57 AM
-
Tuesday, October 13, 2009 3:16 PMAnother way to regenerate your designer file:1. Create another new blank ascx (or aspx, as applicable)2. Switch to design mode in your 'broken' file.3. Select All, and Copy to clipboard4. Paste all the controls into the new file.5. Delete the controls from the original file, and copy and paste the controls back in from the new fileThis just worked great for me.
-
Thursday, October 15, 2009 4:23 AM
None of these work in VS 9.0.30729.1.
This subject covers the number one bug in Visual Studio as far as I'm concerned. I have had more time wasted because of this than any other glitch (the second being the inability to find a clearly specified reference). I have tried all of the aforementioned remedies with no success. The only way to solve this is to include all of the prototypes in my .cs file and abandon the designer file entirely. That's kind of old-school, but it works.
The VStud team really needs to add a "force generate" option into one of the menus to MAKE the tool rebuild everything. -
Friday, October 30, 2009 2:40 AM
I had a similar problem. I noticed that there was no namespace defined in the aspx file nor in the aspx.cs file. I added the declaration to both files and the designer.cs file was generated fine doing the convert to web application.
- Proposed As Answer by joshuaperry Wednesday, June 30, 2010 7:15 AM
-
Monday, December 14, 2009 5:01 AMI also had the problem. Deleting the designer file and running convert to web application on it helped me determine the problem, which was an unallowed html comment within my <table runat="server"> ... </table>. Apparently a table set to runat="server" has strict requirements on its children. Beware.
-
Thursday, January 13, 2011 6:04 PMJust turn on your warnings and actually look at them. What happens is that something in the HTML is incorrect and causing the generation to fail in the first place such as controls with the same name, etc... I spent a while looking at this as well then found that I had 2 controls in the HTML named the same.
-
Wednesday, April 06, 2011 8:29 PMHaha 4 years later, vs.net 2010 and this problem still exists, arrggghhhhhh to say the least, well +1 for convert to application, you can do it on the solution as well if none of your files have a designer, ie when you paste a file into vs.net this happens ummm, well sometimes, but he there is a decent solution, thanks for the fix!!!!
-
Thursday, April 14, 2011 12:43 AM
The generation of the designer file will silently fail if there is some sort of error in your markup. A quick way to diagnose this is to comment out everything in your markup file except the page header. Then you should get an empty designer file. Uncomment your markup bit by bit until the designer file fails to generate. You have now pinpointed where the problem is.
I just had an example where I defined a control using the "<%@ Register" tag that was identical to a definition in web.config.
-
Wednesday, July 20, 2011 3:33 PMThat worked, thanks John!
-
Wednesday, October 12, 2011 12:16 PM
A pain in the #@$$.
Delete the designer.cs page, right click on the aspx/ascx page and choose Convert to Web Application.
Thanks John Q. Smith, your solution worked OK. -
Wednesday, December 21, 2011 1:36 PM

