404

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
Glenn Slaven
  • 31,855
  • 25
  • 107
  • 163
  • 58
    It's it ridiculous that in 2012 Visual Studio still doesn't have a context menu item to regenerate designer files from source files? It's akin to not being able to rebuild a corrupt DLL. I don't understand it.. Especially with external source control and external editors you leave Visual Studio crippled. Waste of money, if you ask me. I'm actually trying to regenerate resource file designers. I managed to get *edit* it regenerated, but it's through obscurity... Augh!!!1 – bambams Nov 21 '12 at 15:06
  • 3
    @bamccaig, if I had a penny for every weird "feature" like this, I would be richer than Bill Gates. If you think this is bad, look at where Outlook Express stores its mail data. It's buried deep in the user folder under a cryptic folder name that's hidden by default. – ATL_DEV Jul 15 '14 at 03:41
  • 13
    Is there any solution for VS 2015? – Anton Oct 25 '15 at 10:19
  • See related http://stackoverflow.com/questions/6508252/designer-cs-not-updating-when-new-controls-added-to-aspx for other attempts. – goodeye Oct 12 '16 at 21:08
  • 2
    Not a permanent fix but this restores control references in the .cs file: 1. Open the related .aspx file; 2. Delete the single ">" at the end of the `" back. 5. Switch over to the .cs file and you'll see it is now free of control reference errors. I've been doing this for ages now, works every time, in every VS version. – ingredient_15939 Mar 01 '17 at 04:55
  • Ran into this in 2012 just now. The other solutions of messing with the designer file, and changing control names did not work. Renaming the page and re-naming it back did trigger the designer files to re-generate/update. – PoloHoleSet May 25 '18 at 15:57
  • @ingredient_15939 VS2019 and your comment did the trick for me. Thanks a ton! – abhi May 06 '20 at 22:21

48 Answers48

376

If you open the .aspx file and switch between design view and html view and back it will prompt VS to check the controls and add any that are missing to the designer file.

In VS2013-15 there is a Convert to Web Application command under the Project menu. Prior to VS2013 this option was available in the right-click context menu for as(c/p)x files. When this is done you should see that you now have a *.Designer.cs file available and your controls within the Design HTML will be available for your control.

PS: This should not be done in debug mode, as not everything is "recompiled" when debugging.

Some people have also reported success by (making a backup copy of your .designer.cs file and then) deleting the .designer.cs file. Re-create an empty file with the same name.

There are many comments to this answer that add tips on how best to re-create the designer.cs file.

qxotk
  • 2,278
  • 4
  • 24
  • 37
Espo
  • 39,502
  • 20
  • 127
  • 156
  • 1
    This only worked for me after closing down every instance (even those with totally different solutions) of VS2008 – Kevin Feb 18 '10 at 17:50
  • 11
    I found that changing from debug mode to release mode dig the trick for me, Thanks – Chris Jun 22 '10 at 16:06
  • I was copying files from a website to a web application and "convert to web application" did it for me. Ta! – Alxwest Apr 11 '12 at 08:42
  • 5
    Just wanted to say that I was having the same error and tried everything on this page, with nothing working. Turned out I was missing a ">" close tag on a div that had runat="server". Running VS-2008. – Ber53rker May 16 '12 at 14:07
  • 10
    To make "Convert to Web Application" appear, first you need to delete the Designer.cs file BY RIGHT CLICKING the aspx file in Solution Explorer and selecting delete. This worked for me in VS 2010. – DeveloperDan May 16 '12 at 21:02
  • the solution "switch between design view and html view" worked for me – ravidev Nov 13 '13 at 13:11
  • 1
    Even worse, in VS2013 "Convert to Web Application" no longer appears. See: https://connect.microsoft.com/VisualStudio/feedback/details/806283/regenerate-the-designer-file-filename-aspx-designer-cs-in-visual-studio-2013# – JohnnyBizzle Jan 30 '14 at 11:37
  • 43
    VS2013 has the Convert to Web Application under the Project menu. Just no longer in the context menu. – Dennis Burton Jul 21 '14 at 19:35
  • @DennisBurton I am using VS2013, and convert to Web Application did the trick for me. I have changed all the namespaces. – Juanito Feb 24 '15 at 09:05
  • @DennisBurton, your comment was the thing that solved my issue. We spent HOURS trying to figure out how to get the context menu option to appear, when all this time, it was right there in the main project menu. Excellent comment, and should be an answer! – Brien Foss Sep 22 '16 at 19:33
  • 1
    To make "Convert to Web Application" appear, the project or solution node has to be selected in solution explorer. Otherwise, its not listed under the project menu. – Tom McDonald Nov 09 '16 at 20:01
  • Removing the designer.cs file and re-adding it manually helped me. Just add the file as an HTML file, name it .designer.cs, remove the HTML content from the file and build. – Jordec Mar 09 '17 at 09:25
  • For me, I had yellow exclamation marks next to all the "within solution project" references. I had to delete the references and add them back. – Vaibhav Garg May 01 '17 at 08:05
  • worked for me (convert to web application) in 2012. You can do it one file at a time if you are being cautious just by right clicking the file. – naskew Oct 15 '17 at 13:28
  • I have been trying this from last 2 hours and unable to get the designer file to get regenerated..are there any other way to force to recreate the designer file. – user1567194 Dec 14 '17 at 15:45
  • If you want to delete designer.cs files, do it from within Visual Studio, and not from the command prompt, otherwise the "Convert to Web Application" will not regenerate the designer.cs files. – desm Jan 24 '18 at 23:31
  • 1
    I may have found a simple solution: 1) Add missing *.designer.cs file and include in project. 2) In ASPX page, change CodeFile= to CodeBehind= 3) Save ASPX page Change CodeBehind= back to CodeFile= – Derek Wade Feb 05 '20 at 07:14
97

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
  • 31,855
  • 25
  • 107
  • 163
  • 3
    This just worked for me too. Not ideal. No idea why the original desginer file stopped updating properly. – Iain Holder Oct 29 '08 at 10:16
  • 3
    This did not work for me. Now I have an empty file and all of the code behind does not work!!! Rebooting... – DiningPhilanderer Mar 19 '09 at 20:25
  • 7
    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 Apr 15 '09 at 21:43
  • 9
    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 Feb 11 '10 at 13:53
  • 1
    I also had to include the empty file in my project. – JP Hellemons Nov 25 '13 at 09:50
  • Thanks for the extra detail @TJB, I tried everything recommended on the internet with no joy. Most recently, opened the designer.vb file in Notepad++ and deleted everything in it and saved it as blank. It still wouldn't regenerate on a Rebuild all. I just added a new div to the .aspx source and saved it, did a rebuild and AT LAST it's working. – Resource Jul 01 '15 at 10:54
  • Thanks for the solution, I had a similar problem. I had generated an ASPX file using Add|New from Template|Aspx with master page. It generated an ASPX file only, this solution was the only way I found to get it to generate the designer file. I also had to manually create the code behind file. I guess I won't use that template again (VS 2015 update 2)... – Scott Gartner May 16 '16 at 19:12
  • If you are still unable to create designer.cs, you should Right Click the aspx file, and "View Desginer". Mine is VS 2013 and it works like a charm – Rocky Andra Sep 01 '16 at 01:52
  • Excellent use of the word *Dodgy*. – Paul Oct 12 '17 at 08:51
  • It is really frustrating why this behavior is not consistent. Once my editing the file worked, once the convert to web application worked and today, I had to create an empty designer file in the folder. I am using VS 2019. – abhi Jun 04 '20 at 23:15
  • What does 'turn on view compile' mean? @DevelopingChris – Jake Gaston Nov 12 '20 at 20:06
80

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
  • 185
  • 1
  • 5
  • 10
65

I recently saw that I was having the same problem. Visual Studio 2010 was refusing to update the designer file.

As it turns out, VS doesn't modify the designer file for a page that uses CodeFile (run off of pages) instead of CodeBehind (DLL). This is true no matter how many times you close VS, reload the project, re-create the control(s), or modify a file. Nothing would prompt VS to regenerate the designer. It's as if it doesn't create the designer file for CodeFile pages but does require it to be there.

I changed it to CodeBehind and saved the page. The designer file updated immediately. Then I just changed it back and everything was still golden. This behavior seems to be new with VS 2010 / .NET 4.0 as VS 2008 by default didn't suffer from this.

It's this part:

<%@ Page Language="vb" AutoEventWireup="false" CodeFile="YourPage.aspx.vb" Inherits="YourPageClass" %>

Change CodeFile to CodeBehind, save, and then revert.

Geoff
  • 111
  • 3
  • 3
  • Late to this thread. None of the answers described above force the controls to be listed in the *.aspx.designer.cs. I was hoping this one would, but it still does not force the controls to be declared in the *.aspx.designer.cs file. I'm using VS 2010 Pro SP1. I'm trying to get this to work with any of the default files that the IDE generates in /Account like ChangePassword.aspx. Thanks. – paparush Oct 31 '11 at 17:12
  • 1
    Mine was set to CodeFile, I changed to CodeBehind, saved, back to CodeFile, saved, everything is Golden. The previous attempts at fixes didn't do it for me. VS 2010 Pro – Daniel Bragg Mar 18 '16 at 21:05
38

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
  • 4,492
  • 6
  • 37
  • 45
  • I had the same problem, the user control had errors so the pages which use the user control had unrelated errors because of the errors in the user control. – Ronen Festinger Nov 28 '13 at 15:15
  • 1
    Same cause. I had an unsupported attribute visible="false" added to an asp button. I removed it and the designer code was re-generated. – chingNotCHing Feb 28 '19 at 03:05
22

Most of the solutions here don't work if you're running Visual Studio 2013 and possibly 2012. Microsoft probably introduced some optimizations to make the IDE snappier, consequently they've reduced the number of cases that trigger the code generator. The following scenarios that used to work no longer do:

  1. Delete the aspx or ascx file -- No longer checks for this case
  2. Cut all the content and repaste into the aspx or ascx file -- No longer works, no change in the references
  3. Convert to Web Application -- Option no longer available
  4. Arbitrarily changing content on the aspx/ascx file -- No longer works (see 2).

The solution is surprisingly simple, but it's slightly cumbersome. In order to trigger the code generator, change something that would require the designer.aspx.cs to be generated. Changing content that doesn't affect code, such as a CSS style or adding text, won't trigger the code generator. You must change a referenced control. Here's how to do it:

In the ascx or aspx change the ID of the control

<asp:HyperLink ID="MyLink" runat="server" NavigateUrl="~/Default.aspx" Text="Home" />

to

<asp:HyperLink ID="theLINK" runat="server" NavigateUrl="~/Default.aspx" CssClass="tab" Text="Home" />

Go to the ascx.cs or aspx.cs and make sure you rename all references to "MyLink" to "theLINK" as well. Save and do build and the you should be good to go.

ATL_DEV
  • 8,679
  • 11
  • 49
  • 94
  • Very good point about changes in newer version of Visual Studio. **What worked for me rather than messing with the ID's like above, was wiping out the designer file, then adding a brand new, benign control such as – Jordan Rieger Jul 14 '14 at 21:29
  • 9
    3. 'Convert to Web Application' is made available in the 'PROJECT' menu if an appropriate file is selected. – WynandB Jul 22 '14 at 07:24
  • 2
    Hmm. Unfortunately, this option isn't available if it's already a web application. – ATL_DEV Jul 23 '14 at 12:19
  • A quick change is to edit the namespace portion of the Inherits= attribute. This should edit the namespace in the .designer file and regenerate all contents inside. I just tried this with VS2013.3. – David Russell Aug 26 '14 at 06:19
  • Hi, I normally try with the way you provided but the problem is another user is not able to generate g.cs file while only administrator is able to do. We are using TFS, with using several developers user id in VS, we're able to generate g.cs. What are the rights required to generate g.cs on server, TFS & SP? – nirav May 21 '15 at 06:42
  • @WynandB, your solution worked for me. If anyone is having problems finding that option in the menu, delete the designer file first before looking there. – Bryan Rayner Jul 13 '15 at 16:35
14

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
  • 36,999
  • 27
  • 83
  • 117
  • 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 Mar 09 '10 at 21:48
  • This worked for me. The code-behind class had an `int Id` property which compiled just fine in C# since it's case sensitive. But `ID="ControlName"` in the aspx page was trying to do `Id = "ControlName"`. `Convert to Web App` said something like `ControlName cannot be converted to Int32`. – Nelson Rothermel Dec 13 '10 at 17:43
9

Convert to Web Application did not work for me.

Deleting designer.cs and pasting a blank designer.cs did not work either.

But yes this worked:

  1. Select all(Default.aspx)
  2. Cut
  3. Save Default.aspx
  4. Paste
  5. Save Default.aspx

Done. New designer.cs generated. :)

PakkuDon
  • 1,631
  • 4
  • 21
  • 21
O D
  • 21
  • 1
  • 7
6

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
  • 7,122
  • 8
  • 41
  • 63
  • 2
    That's the kind of error that i have many times. If you copy HTML from one page to other and have controls with runat="server", controls will be renamed to avoid conflict. However, if you paste inside "html comment" tags , control id's will not be changed, and any conflict will stop designer file to be regenerated, because there are two controls with the same ID. That's because controls inside html "comments" tags are also created. ;) – tomasofen Nov 30 '13 at 20:10
5

I've found a way to solve this problem without changing any code or running commands like "Convert to Web Application" - and it's simple too!

What I found was that restarting Visual Studio often solves the problem, but sometimes it doesn't. In those cases, if you close Visual Studio and then delete all content in the "obj" directory for the web project before you open it again, it has always worked for me.

(when started again you just add a space and remove it again and then hit save to have the designer file properly regenerated)

tommycode
  • 163
  • 3
  • 6
  • I've been having this problem with a legacy app I've been put in charge of supporting. I want to say thank you for pointing this out. I'm not permitted to convert to web application", create a new solution, or do anything but fix bugs. The designer would crash, constantly, for me. But this has helped so far. – Jamie Taylor Jul 11 '13 at 09:24
5

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
  • 3,445
  • 1
  • 23
  • 27
  • Added this attribute then saved; nothing. Then removed the Inherits, saved, restored and voila the designer code file was updated! This irksome feature catches me every time:-( – GlennG May 11 '12 at 13:52
  • both links are dead =( – Maslow Feb 12 '14 at 21:48
4

Another thing which worked was -

  1. Manually delete & then Create a designer file in filesystem.
  2. Edit Project file.
  3. Add code to include designer
    Eg: <Compile Include="<Path>\FileName.ascx.designer.cs"> <DependentUpon>FileName.ascx</DependentUpon> </Compile>
  4. Reload Project
  5. Open as(c/p)x file in design/view mode & save it.
  6. Check designer file. Code will be there.
Vandesh
  • 4,638
  • 1
  • 20
  • 30
4

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

yertle
  • 11
  • 1
4

(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
  • 16,328
  • 8
  • 49
  • 79
  • Ran into this with VS.Net 2010... had to do exactly this... Thanks @EndangeredMassa for the tip... I used to go through this in the VS.Net 2002/2003 days as well... Wish I knew this then ;) – Richard B Jun 02 '11 at 12:47
3

If you are using VS2013 or later , make sure that the code referenced with attribute "CodeBehind" not "CodeFile", then do below steps

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="yourControl.ascx.cs" Inherits="yourControl.yourControl" %>
  • create empty designer page (or clear it if it's already exists "yourControl.ascx.designer.cs")
  • in the ascx (or aspx) copy all code , the delete it, then save. re-past it again , then save.
  • the designer file should be populated now.
Tarek El-Mallah
  • 3,630
  • 1
  • 28
  • 42
2

Just to add to the long list of answers here - I've just run into this issue in VS2010 (SP1) with an .aspx file. I tried adding and removing standard ASP controls (which has worked in the past) but in the end, I had to remove one of the runat=server lines from an existing control (and save) to force the designer file to regenerate.

Rory Solley
  • 1,395
  • 1
  • 8
  • 6
2

I've encountered the same problem for years now, working in Visual Studio 2008. And I've tried every "solution" on StackOverflow and dozens of blogs, just like I'm sure all of you have. And sometimes they work, and sometimes they don't, just like I'm sure all of you have encountered. And apparently it's still an issue in VS2010 and VS2012.

So finally, a couple of months ago, I decided enough was enough, and over a few weeks I built a tool called "Redesigner" that generates .designer files. It's open-source under the BSD license, with the source code available on SourceForge — free to use, free to steal, free to do anything you please with. And it does what Visual Studio fails to do so often, which is generate .designer files quickly and reliably.

It's a stand-alone command-line tool that parses .aspx and .ascx files, performs all the necessary reflection magic, and spits out correct .designer files. It does all the parsing and reflection itself to avoid relying on existing code, which we all know too well is broken. It's written in C# against .NET 3.5, but it makes pains to avoid using even System.Web for anything other than type declarations, and it doesn't use or rely on Visual Studio at all.

Redesigner can generate new .designer files; and it offers a --verbose option so that when things go wrong, you get far better error messages than "Exception of type System.Exception was thrown." And there's a --verify option that can be used to tell you when your existing .designer files are broken — missing controls, bad property declarations, unreadable by Visual Studio, or otherwise just plain borked.

We've been using it at my workplace to get us out of jams for the better part of the last month now, and while Redesigner is still a beta, it's getting far enough along that it's worth sharing its existence with the public. I soon intend to create a Visual Studio plugin for it so you can simply right-click to verify or regenerate designer files the way you always wished you could. But in the interim, the command-line usage is pretty easy and will save you a lot of headaches.

Anyway, go download a copy of Redesigner now and stop pulling out your hair. You won't always need it, but when you do, you'll be glad you have it!

https://sourceforge.net/projects/redesigner/

Sean Werkema
  • 3,386
  • 1
  • 27
  • 36
2
  • 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
  • 94,042
  • 31
  • 216
  • 230
  • 1
    This worked for me! I also saved the .aspx file after cutting everything out. Pasted back in, saved, and my (previously blank) designer file was fully populated. – DaveD Mar 18 '12 at 20:46
2

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
  • 1,495
  • 3
  • 20
  • 31
2

TL;DR;
Edit the Inherits attribute of the ASPX page's @Page directive and hit Save. Your designer file should be regenerated.

Ensure that Inherits = <namespace>.<class_name> and CodeBehind = <class_name>.aspx.cs


I was trying to do this on a Sharepoint 2010 project, using VS 2010 and TFS, and none of the solutions above worked for me. Primarily, the option, "Convert to Web Application" is missing from the right-click menu of the .ASPX file when using TFS in VS 2010.

This answer helped finally. My class looked like this:

namespace MyProjects.Finance.Pages
{
    public partial class FinanceSubmission : WebPartPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        // more code
    }
}

And my @Page directive was (line-breaks here for clarity):

<%@ Page Language="C#" AutoEventWireup="true" 
    CodeBehind="FinanceSubmission.aspx.cs"
    Inherits="MyProjects.Finance.Pages.FinanceSubmission"
    MasterPageFile="~masterurl/default.master" %>

I first changed the Inherits to MyProjects.Finance.Pages, hit Save, then changed it back to MyProjects.Finance.Pages.FinanceSubmission and hit Save again. And wallah! The designer page was regenerated!

Hope this helps someone using TFS!

Community
  • 1
  • 1
SNag
  • 15,558
  • 10
  • 45
  • 63
2

Within the Visual Studio:

1) Remove your aspx.designer.cs file

2) Right click on your aspx file and select "Convert to Web Application" This should add the aspx.designer.cs back and up to date.

If you get an error saying:

"Generation of designer file failed: The method or operation is not implemented."

Try close Visual Studio and then reopen your project and do step number two again

How to generate aspx.designer.cs in visual studio?

Community
  • 1
  • 1
nouman arshad
  • 433
  • 5
  • 15
  • 2
    "Convert to Web Application" does not exist on the context menu of an aspx file. At least, it doesn't in VS Professional 2015. – Chris Walsh Nov 26 '15 at 01:37
2

in solution explorer just right click and select convert to web application. It will generate all the designer files again.

user3911976
  • 65
  • 2
  • 10
  • Select the aspx file, expand, and on the top project menu, click on the convert to web option. – fcm Feb 12 '21 at 12:19
2
  1. Step 1: Select all your aspx code, Cut [ CTRL+X ] that code and Save.

  2. Step 2: Again paste the same code in the same page and save again

Now your .desinger page will refresh with all controls in .aspx page.

Sampat
  • 58
  • 1
  • 1
  • 7
1

One thing that nobody's mentioned is to visit the page. I had my designer file stop regenerating because I was including a user control that didn't exist (for various reasons), and none of the things suggested here worked. For whatever reason, I didn't get any errors in Visual Studio - besides the one complaining about the fact that my client-side controls didn't exist because they weren't being regenerated, of course.

It took actually visiting the page to get ASP.Net to tell me the error.

Tacroy
  • 375
  • 2
  • 13
1

The solution the worked for me is:

I just copied the page and and pasted it in the same portion, then renamed the first page(what ever name) and renamed the copied page as the original page. Now the controls are accessible.

jonsca
  • 9,342
  • 26
  • 53
  • 60
you y
  • 1
  • 1
1

This can also happen if you update the namespace and don't update the namespace in the designer file. Fix: Update the namespace in the designer file too.

Ben Weeks
  • 1
  • 1
1

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
  • 11
  • 1
1

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

user381377
  • 11
  • 1
1
  1. Close designer.cs.

  2. Change your aspx file to design view.

  3. Right-Click –> Refresh.

  4. Save

Glaucyo Ricas
  • 61
  • 1
  • 3
1

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

If you are like me and you add old .ASPX files to a more recent project. You are probably going to forget some of the controls used on the page.

If so, first thing, if there are multiple files you are installing; Fix one at a time first.

When you compile, fix errors generated. They will probably be the same errors in all the files.

Next, if you have Designer files, delete all of the inserted - designer files. Next, make sure there are not any other errors when you compile, other than the designer files.

Finally right click your web project and click on Convert to Web Application. This will insert the designer files you need.

These are the absolute best steps to fix the issues.

Tim Cooper
  • 144,163
  • 35
  • 302
  • 261
Carlo
  • 11
  • 1
1

I had the problem that my new controls would not generate in the designer file when declared in the .ascx file. The problem was that i declared them in the code behind also. So deleting the declaration in the code behind solved my problem.

The Demz
  • 6,336
  • 4
  • 33
  • 42
0

I know this is an old topic but I just wanted to add a solution that wasn't suggested yet.

I had the same problem with a resource file. I edited it outside Visual Studio and the designer file hadn't updated properly.

Renaming the file did the trick of regenerating the Designer file. I just renamed it to the initial name again and that worked just fine!

Aries51
  • 369
  • 1
  • 8
0

I'm in VS 2003 and none of these worked for me. What worked was to open the code at the top of the .vb page in the section labeled Web Form Designer Generated Code (the part that says not to edit there) and declare it there, where the system declared all the other controls. Bizzare.

Joanne
  • 1
0
  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.
0

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
  • 1
0

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

amac44
  • 103
  • 1
  • 7
0

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.

VoltaicShock
  • 856
  • 2
  • 6
  • 15
0

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
  • 921
  • 6
  • 6
0

For VS2015... here's a VB example for switching from a WebSite project to a Web Application Project that worked for me. None of the other solutions worked for me, which is why I'm sharing this. It's not elegant, but works.

Step 0: Replace all " CodeFile=" with " CodeBehind=" in your project Step 1: Close the Solution. Step 2: Run a home-grown Windows app with the following code (below steps). Step 3: Re-open the solution. Step 4: In Solution Explorer, make sure you are Showing All Files, and search for designer.vb (or designer.cs for C#) Step 5: Select all the missing files, and include them in your project. Step 6: For each file, view the main page / control and save it.

    private void button1_Click(object sender, EventArgs e)
    {
        ProcessDirectory(new DirectoryInfo(textBox1.Text));
    }

    private void ProcessDirectory(DirectoryInfo directory)
    {
        ProcessMask(directory, ".ascx", ".vb");
        ProcessMask(directory, ".aspx", ".vb");

        foreach (DirectoryInfo directoryInfo in directory.GetDirectories())
            ProcessDirectory(directoryInfo);
    }

    private void ProcessMask(DirectoryInfo directory, string maskStart, string maskEnd)
    {
        FileStream fs;
        foreach (FileInfo file in directory.GetFiles(string.Format("*{0}{1}", maskStart, maskEnd)))
        {
            string designerFileName = file.Name.Replace(string.Format("{0}{1}", maskStart, maskEnd), string.Format("{0}.designer{1}", maskStart, maskEnd));
            if (directory.GetFiles(designerFileName).Length == 0)
            {
                using (fs = File.Create(Path.Combine(directory.FullName, designerFileName)))
                {
                    fs.Close();
                }
            }
        }
    }
0

Apart from all the good answers already given, I'd like to add to @johan-leino's great answer. In my case, for some arbitrary reason, the CodeBehind attribute was omitted from the @Page directive/.aspx file. Likewise, it might be worthwhile to check the CodeFile attribute for @Control directives/.ascx files (obviously in conjunction with an Inherits attribute in both cases).

Depending on the exact scenario and reason required to 'force' a regenerate of .designer.cs, one could also try to format the document (potentially indicating a parsing error) before (quick) saving (regardless whether there were any changes or not) and check the Error List for warnings.

WynandB
  • 1,267
  • 13
  • 15
0

I thought I had this problem and was tearing my hair out, but then I realised that I was trying to reference a control from a static method.

Making the method non-static resolved the issue for me.

WonderWorker
  • 7,388
  • 3
  • 52
  • 71
0

One of my solution, which works for me.

  1. Close the Visual Studio
  2. Remove hidden .vs directory
  3. Remove existing .sln file
  4. load the project in visual studio using .csproj file
Niaz Morshed
  • 161
  • 1
  • 3
0

In my case, it was fixed when I added a CodeBehind to the @Page section.

0

I know I'm late to the party, but I thought if after trying the accepted answer by @Glenn Slaven and the current highest rated answer by @Espo you are still out of luck, the following might save some people out there some trouble.

User Controls (.ascx) are what constantly stop auto-generating for me. I've found that in the instances where I use other User Control(s) in my User Control, it breaks the auto-generation.

The solution I came up with was to use the trick we all know of for getting IntelliSense to work in User Controls or Skin files when using CSS classes from external sources. Instead of just referencing the CSS file, now I Register the other User Control(s) that I need. It looks something like this:

<% If False Then %>
<%@ Register TagPrefix="uc" TagName="Title" Src="~/controls/title.ascx" %>
<link rel="stylesheet" type="text/css" href="../css/common.css"  />
<% End If %>

After that, I Save the file, which prompts the auto-generation to regenerate, and I'm back up and running.

Code Maverick
  • 19,231
  • 10
  • 57
  • 111
0

In Visual Studio 2019 below are the steps:

  1. Create webform1.aspx
  2. Copy your aspx code and paste in webform1.aspx
  3. Compile your project you should have designer code inside webform1.aspx.designer.cs
  4. Now you can copy designer code and use in your original webform.
0

If you see this while using Visual Basic 2019 and you clicked on the "permanently delete this file" confirmation, you can recover the designer.cs files from your recycle bin...it will regenerate in Visual Basic automatically. I just did it and found my file just as it was.

Tiptop
  • 1
  • 2
0

The solution was for me to change from None to Compile in .csproj file

<Compile Include="Logout.aspx.designer.cs">
      <DependentUpon>Logout.aspx</DependentUpon>
</Compile>
Bimal Das
  • 1,682
  • 4
  • 25
  • 47