43

I just deleted a designer.cs file from a aspx page.. (Don't ask how I can do that.. You don't really want to know..) Is it a way to regenerate the file for the aspx page? I was hoping that something like "right-click/ generate designer" exists but it is not the case.. :-(

So thanks if somebody have an idea..

bAN
  • 11,925
  • 15
  • 56
  • 90

7 Answers7

89

Find another solution to my Question, right-click on the aspx file, then choose "convert to web application" and then, the designer.cs file is regenerated..

It is more easier and quick..


This option is no longer available in VS2013, but you can accomplish the same thing by selecting your project in the Solution Explorer, then going to the Project option on the Menu Bar. Near the bottom you will see the Convert to Web Application option. This will generate designer files for all the *.aspx pages in your project that don't have them, but be aware that this may not be what you want if you have a mix of CodeFile *.aspx pages and CodeBehind files. This will also convert CodeFile pages to CodeBehind files. (Courtesy Joisey Mike)

Community
  • 1
  • 1
bAN
  • 11,925
  • 15
  • 56
  • 90
  • 4
    This is available they have just removed the option from the context menu (right clicking) You can find it under Visual studios Main top menu under Project. – Jessy Jan 09 '16 at 01:39
  • This worked. However, I was also converting from vb -> cs, so in the aspx file I had to ensure the correct extension on the codefile / codebehind = "MyPage.aspx.cs". If it can't find the file, it does not work. – emragins Dec 04 '16 at 03:54
  • In VS2017. The option I get is only *Convert to Azure Cloud Service*. Is there any work around for that? – Jamshaid K. Sep 30 '17 at 20:46
15

Open the designer and save (you might have to change something in the markup before being able to save). It should be recreated. Event subscriptions and other settings only kept in the designer won't be possible restore though.

EDIT: Make sure that the designer file exists by creating an empty file with just the partial class definition. Also make sure that it's registered in the project file. Then open the designer or the aspx page and make one small change (insert a space in the aspx) and save it. Now the designer file should be recreated.

PHeiberg
  • 28,455
  • 6
  • 51
  • 79
  • 6
    I've tried it but it doesn't work.. – bAN Feb 21 '11 at 13:42
  • @bAN: See my edit. Tried it successfully using VS2008. – PHeiberg Feb 21 '11 at 13:52
  • 1
    Worked for me in VS 2010. I was regenning an .ascx designer file, so this solution has the double benefit of working for non .aspx files with designer files. – kmkemp Dec 19 '11 at 15:57
  • Creating a shell designer file first by adding a shell partial class definition, then making a token edit to the aspx page did the trick for me in VS2013 Ultimate. You can also exclude the aspx from the project, then re-include it, and that will update the shell designer partial class file. – David W May 14 '15 at 15:01
  • creating the designer file as a partial class with the proper naming convention worked great for me in VS2013 Ultimate – Mark May 26 '16 at 14:46
  • This worked great for me. I'm using VS2017 – Joe Salazar Jan 26 '18 at 12:44
1

Use R-Studio from http://www.r-tt.com and undelete it. Use Source Control in the future.

Part from that, try copying the GUI controls into a new page and copy the content of its Designer page to your deleted one.

Tedd Hansen
  • 11,020
  • 14
  • 57
  • 93
1

If editing and saving your aspx file doesn't work, try the following:

  1. Restart Visual Studio
  2. Ensure there are no errors in your aspx file (e.g. missing <%@ Register ... %> tags)

Having ReSharper installed helps with step 2 as it prompts to automatically register missing user controls (but in my case, only after a restart).

This worked for me in Visual Studio 2008.

Dunc
  • 16,506
  • 6
  • 74
  • 95
0

Along with all the other suggestions:

In my case, it was a user control that began missing it's designer file. So, in the ascx, I commented out all the content, leaving only the Assembly,Register, and Import headers. I then rebuilt the solution. With that success, I had new designer code auto generated. I removed the comments and rebuilt again. Everything was back in the place it should be.

Your mileage may vary.

Mike T
  • 3,016
  • 4
  • 19
  • 21
0

View in browser should recreate it.

Pabuc
  • 5,430
  • 6
  • 33
  • 51
  • It doesn't work.. Maybe as you said it is because he is DELETED – bAN Feb 21 '11 at 13:39
  • ok, the last thing is rebuilding the entire solution. If it doesn't work, I have no other ideas. – Pabuc Feb 21 '11 at 13:41
  • Bouuuuuuuh :-( it doesn't work.. – bAN Feb 21 '11 at 13:43
  • Do you get run time error - build error when you try what I suggested? First should give runtime second should give build error if itsn't working – Pabuc Feb 21 '11 at 13:45
  • If you still haven't closed VS, try ctrl+z all the way back. You might get it back that way too :) – Pabuc Feb 21 '11 at 13:46
  • lol, I have tried around 20 ctrl+z but it doesn't work for file deleting.. – bAN Feb 21 '11 at 13:55
-2

Edit: It should be able to recreate it somehow. However my tip still stands: use source control. Some time in the future, you will delete something vital and can't restore it via any means, and then you will be grateful for having source control.

Femaref
  • 58,195
  • 7
  • 126
  • 170
  • The aspx page sometimes can sort things out. Happened to me a lot, with creating controls by drag&drop, it may not be added to designer and you can't use it in code behind. For me view in browser always fixed that error. But as you said, *deleting* it maybe something else.. – Pabuc Feb 21 '11 at 13:36
  • Is for asp.net, webforms, designer.cs for a aspx page is a partial class who contains definitions for asp controls in the aspx file. – bAN Feb 21 '11 at 13:38
  • In ASP.NET, it's possible to recreate the designer file, since it's generated from the ASPX-page. – PHeiberg Feb 21 '11 at 13:39
  • 1
    not relevant to the question. – greg Sep 22 '16 at 22:13