35

My current aspx.designer.cs is not working properly, does anybody have any idea about regenerating aspx.designer.cs in solution explorer.

  • 1
    What do you mean by "is not working properly"? – kostas ch. Dec 31 '13 at 13:32
  • I was refactoring a very old WebForms and found that a) make sure on the file property select 'Compile' and b) select the .aspx and on the menu project, convert to Application. – fcm May 05 '20 at 20:03

1 Answers1

74

Found here:


Update (based on comment from @Gone Coding):

Suggestion: Back up your [page-name].aspx.designer.cs file(s) before making any of the changes described below.


Within the Visual Studio:

1) Remove your aspx.designer.cs file

2) Right click on your aspx file and select "Convert to Web Application"
      or for VS2017
   click on your aspx file and then from Project menu, click "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

And here:

Missing or corrupted designer file causes Visual studio (VS) to fail the build. This is because without designer file VS is unable to find the declarations of controls. Also most of the time controls are not added to designer.cs giving build errors.

To fix this issue, Below is the simplest solution I know:

  1. Delete your designer file if it is corrupted else start from step2.
  2. Go to your aspx markup (source) page and find below line of code. <%@ Page Language="C#" AutoEventWireup="false" CodeFile="SamplePage.aspx.cs" Inherits=" SamplePageClass" %>
  3. Now change CodeFile tag to CodeBehind.
  4. Save the file.
  5. Rebuild your project (This will create designer file for your page)
  6. Revert your change (Step3).
qxotk
  • 2,278
  • 4
  • 24
  • 37
Nagaraj S
  • 12,563
  • 6
  • 30
  • 50
  • 2
    I am using Visual Studio 2012 Express edition, when I Right click on aspx file the option "Convert To Web Application" is not available there. What should I do now? – Mohammad Shafi Shaikh Jan 01 '14 at 03:54
  • 20
    **Step 1 Should read: Backup your `aspx.designer.cs` file first!** These instructions **DO NOT WORK** on more recent versions of Visual Studio. – Gone Coding Jun 13 '14 at 09:12
  • @TrueBlueAussie in Visual Studio 2013 its working! – Mox Shah Jan 09 '15 at 07:12
  • 3
    Not working in VS 2013!! – Vlado Pandžić Nov 19 '15 at 20:27
  • What about **ascx**.designer.cs ???? – Cristian E. Feb 01 '16 at 10:54
  • 48
    Note that in Visual Studio 2015, this option is no longer in the right-click menu. It can be found in the main menu under Project -> Convert to Web Application when you have a .aspx file selected in solution explorer. – AaronSieb Nov 10 '16 at 22:07
  • AaronSieb's comment also works for VS Professional 2013 version 12.0.40629.00 Update 5 – Deepak Agrawal Sep 11 '18 at 15:03
  • 5
    Anyone knows how to achieve this in VS 2019? – Shimmy Weitzhandler Aug 05 '19 at 02:40
  • 2
    @Shimmy Same like AaronSieb described in VS 2019. – niketan Oct 11 '19 at 13:57
  • @GoneCoding I added your suggestion to the answer - very good idea in my opinion. – qxotk Dec 03 '19 at 20:03
  • Thank you very much. I have moved old webform application to asp.net mix version. You can convert single file or complete folder to web application. – Ali Aug 25 '20 at 04:26
  • On Visual Studio 2019 Step 1 select the Example.aspx.designer.cs Step 2 Right click and select delete. Choose yes Step 3 The file has been deleted. Step 4 Now we regenerate the file. • Select the aspx file • On the Menu select Project and click Convert to Web Application • Click yes Step 5 The file is regenerated – Sydney_dev May 23 '21 at 20:43