when I used to create ASP.NET website there was only one code behind file as for example Default.aspx.cs. Meanwhile I created ASP.NET web application, this time visual studio generated an additional code behind file as Default.aspx.designer.cs My question why do I need it ? I inherited a class other than the Page class, so I removed "inherits="MySite.Default". But I've got an error mentioning identifier expected in the Default.aspx.designer.cs file. Please help me in this regard too.
Asked
Active
Viewed 6,630 times
2
-
1`.designer.cs` has the declaration of the objects used at your markup. It's a partial class, the same from the code-behind file. If you remove it, VS won't be able to bind your controls from the markup to the code. – Andre Calil Aug 03 '12 at 19:32
-
@AndreCalil- I inherited a class other than the Page class, so I removed "inherits="MySite.Default". But I've got an error mentioning identifier expected in the Default.aspx.designer.cs file. Please help me in this regard too – Md. Arafat Al Mahmud Aug 03 '12 at 19:34
-
I believe that you must have created a new class (let's say, `MyBasePage`). This class **must** inherit from `Page`. Then you go to your **codebehind** file and change the inheritance from `Page` to `MyBasePage`. That's all, you don't have to change anything at the markup. – Andre Calil Aug 03 '12 at 19:36
-
@AndreCalil- But when I ran it on a browser I've got this error: Parser Error Message: 'ThePhile.Default' is not allowed here because it does not extend class 'System.Web.UI.Page'. – Md. Arafat Al Mahmud Aug 03 '12 at 19:41
-
@Md.ArafatAlMahmud Well, yeah, whatever your page inherits from **must** inherit from `System.Web.UI.Page` at some point. I think you need a primer on ASP .NET WebForms development in general... – Yuck Aug 03 '12 at 19:42
-
1Is there a reason you need to use a Web Application rather than a Website? A web application requires you to compile a DLL for any changes. You might be better off creating 1 solution with a website project and a class library project. That would allow you to make smaller, web-based changes without compiling. – CoderMarkus Aug 03 '12 at 22:21
1 Answers
2
the designer files are auto-generated by visual studio and act like scaffolding for the code you write within the aspx and aspx.cs files. Because these are auto-generated you never need to or should touch these files.
I would advise you put the code back where it was, inherit from your desired other class as you wish and let visual studio worry about the designer file.
Simply make the changes your need to those the aspx and aspx.cs files and forget about the designer files.
Find more info here: aspx.designer.cs how does it work?

Community
- 1
- 1

Luke Baughan
- 4,658
- 3
- 31
- 54