views:

11706

answers:

20

Sometimes when I'm editing page or control the .designer files stop being updated with the new controls I'm putting on the page. I'm not sure what's causing this to happen, but I'm wondering if there's any way of forcing Visual Studio to regenerate the .designer file. I'm using Visual Studio 2008

EDIT: Sorry I should have noted I've already tried:

  • Closing & re-opening all the files & Visual Studio
  • Making a change to a runat="server" control on the page
  • Deleting & re-adding the page directive
+16  A: 
Espo
This only worked for me after closing down every instance (even those with totally different solutions) of VS2008
Kevin
this worked for me +1
Naeem Sarfraz
I found that changing from debug mode to release mode dig the trick for me, Thanks
Chris
This worked for me. Greaaaaate thread anyway
Sergej Andrejev
+1  A: 

(The following comes from experience with VS2005.)

If you edit an ASPX page while debugging, then the codebehind doesn't get updated with the new classes. So, you have to stop debugging, trivially edit the ASPX page (like add a button or something), then click Design View, then delete the button. Then, your designer files should be updated.

If you are having a different issue with VS2008, then I can't help.

EndangeredMassa
+14  A: 

Well I found a solution that works, though I don't really like it. I had to delete the .designer.cs file then recreate an empty file with the same name. When I went back in and saved the aspx file again, the designer file was re-generated.

Dodgy!

Glenn Slaven
This just worked for me too. Not ideal. No idea why the original desginer file stopped updating properly.
IainMH
This did not work for me. Now I have an empty file and all of the code behind does not work!!! Rebooting...
Dining Philanderer
This worked for me. I made sure to delete the original, create a new designer.cs file with the same name, close the new file, modify the .as(p/c)x file slightly to force a save, then it was all good.
TJB
Thank you thank you thank you ... I was going crazy with this problem in my project - wasted a whole day on it before finding your answer!
Shaul
if you have a view compile error, it won't come back. Generally thats why it stops regening in the first place. You need to turn on view compile to see it, which is not straight forward.
DevelopingChris
Dodgy indeed... This is a decent solution for developers who do not use Microsoft's source control, but it's dangerous for those of us who do (such as TFS).
danyim
I am using TFS, I don't see why it's more dangerous with TFS than with say subversion though
Glenn Slaven
+3  A: 

the only way I know is to delete the designer file, and do a convert to web app. However when you do this, it usually pops up with the error, as to why it didn't auto-regen in the first place, its usually a control ref that isn't declared in the head of the page.

DevelopingChris
This worked perfectly. Should be the accepted answer imho
Garry Harthill
Doesn't work in VS2008
Carlos Rendon
Sorry it didn't work, its worked in VS 2008 for me since I started using it. Is there a syntax error in your page? You should get a dialogue box that tells you what to fix to finish it working.
DevelopingChris
+12  A: 

There is another possibility: You may have an error in your .aspx file that does not allow Visual Studio to regenerate the designer.

If you switch to Design View, it will show the control as unable to be rendered. Fixing the control (in my case it was an extra quote in the properties) and recompiling should regenerate the designer.

y0mbo
+1 thank you - that helped me!
Shaul
A: 
  • Select-all in the designer file and delete everything in the file, leaving it blank and then save
  • Select-all in the ASPX/ASCX file and cut everything and then re-paste it back
  • The designer file should have regenerated the code
Mark Cidade
This did not work for me.
Zack Peterson
+4  A: 

I use the following method which works everytime:

  • Select all of the code-in-front (html markup etc) in the editor of the aspx/ascx file.
  • Cut.
  • Save.
  • Paste.
  • Save.

Recompile.

Ruvan Fernando
I think just deleting a single control and re-adding it has the same effect.
chris
+1  A: 

Delete the designer.cs file and then right click on the .aspx file and choose "Convert To Web Application". If there is a problem with your control declarations, such as a tag not being well-formed, you will get an error message and you will need to correct the malformed tag before visual studio can successfully re-generate your designer file.

In my case, at this point, I discovered that the problem was that I had declared a button control that that was not inside of a form tag with a runat="server" attribute.

+1  A: 

My experience is that if you want to do like in this article, like stated above.

Your markup file (aspx/ascx) has to include the CodeBehind="MyPage.aspx.cs" attribute or else it won´t work. I blogged about it here.

Johan Leino
+1 Fixed it for me. My page was missing this attribute
Rafe Lavelle
+1  A: 

I often found that copy/pasting caused this behaviour for me. Most cases can be solved by editing the ID of a server control (just add a character, then delete it).

Also remember that control inside things like Repeaters aren't visible in the designer file.

And yes, there are cases where you need to do the delete-the-file magic listed above - but the name-change solution will work most of the time.

Overflew
A: 

Hi All,

Here is wat i experienced , Select the website folder right click in the Solution Explorer, select Convert to Web application for all the aspx file a designer file will get generated.

Sameer

sameer
A: 
  1. replace your custom tag with a invalid tag name. Save it
  2. restore the invalid tag name back to custom tag name. Save it. Then you will be prompted to checkout the *.designer.cs files(or silently modify the designer.cs) and produce correct variable of custom tag control.
osexp2000
A: 

I had this problem and for me, I had a space in one of my ID values for one of my controls. I took the space out and the designer file regenerated itself.

Ritter
A: 

This is a bug in the IDE; I've seen it since VS 2003. THe solution is simple though.

Save your files. Completely exit the IDE (make sure the process stops, task mgr.)

Reopen the solution, dirty the markup, save. Fixed.

bcweis
A: 

In my case I was just missing a register TagPrefix at the top. Somehow the previous dev worked without having this in there?

amac44
A: 

I have had this issue before. I usually just hit enter to add a line and then wait for the plus/minus to show on the html page and the designer should add what you need. I have also had to close the project and reopen it to get it to work.

Terry
A: 

I had two problems... outdated AJAXControlkit - deleted the old dll, removed old controls from toolbox, downloaded new version, loaded toolbox, and dragged and dropped new controls on the page (see http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Studio_.NET_2005/Q_24591597.html)

Also had misspelling in my label control (had used 'class' instead of 'cssclass').

Ta

A: 

I had a similar problem with a user control which contained other user controls. Dirtying the markup didn't help. Deleting the ascx.designer.cs, then creating a new empty one worked a treat. Thanks.

Craig
A: 

I've had this problem a lot, and just did again. I tried fixing it using these suggestions, and nothing worked. I finally found that I had the 'Title' attribute in the page header twice(I added to the end, not realizing that VS added a blank Title="" to the beginning)-- removing the extra attribute caused VS2008 to re-generate the designer file... I hope VS2010 fixes this problem, letting us know why the designer file generation isn't happening...

-- Derek

Derek Kalweit
A: 

When you are in design view, right click on the screen and hit refresh.

yertle