why do I need Default.aspx.designer.cs file? - c#

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.

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?

Related

MvcBuildViews ignore ascx and aspx and compile only cshtml

In a Siteocre project I want to compile all cshtml files using the MvcBuildViews setting. Unfortunately this also compiles any ascx and aspx files. I get an error like :
32>/temp/Sitecore/admin/Wizard/InstallationLog.ascx(1): error
ASPPARSE: The base class includes the field 'logPanel', but its type
(System.Web.UI.HtmlControls.HtmlGenericControl) is not compatible with
the type of control (System.Web.UI.HtmlControls.HtmlIframe).
Is there a way to restrict the view compilation to cshtml only?
I will transform my comment into an answer.
Your approach to have Sitecore inside your Visual Studio folder is not correct.
You need to separate your Visual Studio and website folder where IIS is mapping your site.
On next link is explained very well how to create a Visual Studio Project for Sitecore MVC .
http://sitecore-community.github.io/docs/sitecore-mvc/creating-project/

What kind of .cs extention file include both design and code? C#

I have 2 question.
1.When I create new form with Visual studio then Form design and code are separate files.
Form1.cs
Form1.Designer.cs
Form1.resx
But I downloaded "sample_client.cs" from internet which has both design and code in same "sample_client.cs" file.Why is that? Was it made by Visual Studio or not?
Why some Windows form source is XAML?
Is there something special about it?
One question a time:
Form1.cs and Form1.Designer.cs contain the same class as Partial Class. The second is updated by the IDE itself, the first one by the developer. The example you downloaded probably comes from an other development environments. To discover which is, you have to open the project file and dig into it...
The XAML files belong to the Windows Presentation Foundation (WPF) technology, the example you provided with ".cs .resx" file belongs to Windows Forms technology.
There is a language feature in C# that allows classes to be split into multiple files by using the "partial" keyword.
This is mostly used for splitting a class in an auto-generated part and a user defined part. It can be a good thing to separate user code from the auto-generated to avoid custom code to get overwritten by the generator. This is why the Visual Studio designer splits the same Forms class in a .designer.cs part and a .cs part.
The .designer.cs file is really just plain code for initializing the Form and since it is the same class it can be merged into one file, which is probably what someone has done here.

Role of Designer.cs File in c#

I am getting Designer.cs file in my project and the comment in the file says it is being generated by an automatic tool.
This was an existing project so I don't know much about that. It is generated for one schema.cs which consists of schemas of all the tables in Database.
I am using a SQLIte DB.
Can any one help me in understanding what is the use of the Designer.cs file in a C# project.
There are lots of kinds of Designer.cs files in a Visual Studio project. Common ones are:
Properties\Resources.resx\Resources.Designer.cs file, the auto-generated code from adding resources to the Project + Resources tab
Properties\Settings.settings\Settings.Designer.cs file, the auto-generated code from adding settings to the Project + Settings tab
SomeForm.cs\SomeForm.Designer.cs, the auto-generated code produced by the Winforms designer from the controls you drop on a form
SomeData.xsd\SomeData.Designer.cs, the auto-generated code produced by the dataset designer.
Given that you name a database in your question it is somewhat likely that you are talking about the last one. You ought to see the pattern from the descriptions, you use a visual designer gadget in Visual Studio and it produces C# code that does something useful at runtime. You go back from the Designer.cs to the designer gadget by double-clicking its parent node in the Solution Explorer window. Don't ever edit the Designer.cs file, you'll lose everything when the designer re-generates the code. They are somewhat hidden in the Solution Explorer for that reason. If you haven't found them yet: open the nodes to see them.
Designer.cs contains the declaration and initialization of UI controls and layout of form. The form is rendered based on the information provided in designer.cs. This file is autogenerate when a form is created in design mode.

Migrating from ASP.NET 4 website project to web application project in Visual Studio 2010 Causing all controls to throw error?

I recently updated my VS2010 website project from .NET 3.5 to 4.0. Everything was working fine in the website project. Today I decided to migrate the website to a web application project as I have learned this is the best way to work in .NET. I split out all my class files into a separate class library and copied all my other content into my new project. Then I updated all the references and web.config.
When I build the class library, everything works great.
The problem is happening when I try to build/debug the web application project. It is acting like all the controls are missing and it is also throwing a bunch of compile errors about the public properties I have in my master pages.
Control errors:
"The name 'INSERT CONTROL NAME HERE' does not exist in the current context"
Master page errors:
'System.Web.UI.MasterPage' does not contain a definition....
It is giving these errors for every single control and master page property in my entire solution.
I notice when I add a new web.form to this project, it also adds a filename.aspx.designer.cs file in addition to the .aspx and .aspx.cs file. My existing files do not have these extra files since they were created in a different .NET version.
Anyone have an idea on how to overcome these issues?
UPDATE: It seems I was missing the step where I need to right click on the new application folder and select "Convert to web application". I just did that and it seems to be a little bit better...
Now it is choking on Literals that are inside single quotes:
<div class='<asp:Literal ID="CssClassLiteral" runat="server"></asp:Literal>'>
It doesn't see this literal when it does the conversion... Is the above valid code or should I implement that functionality another way?
Yes - one of the main differences between the website project and a web application project in Visual Studio is that the web application project defines a designer.cs file for every page/user control.
So, let's say you have a page in a website with a codebehind:
Default.aspx
Default.aspx.cs
In a web application, the designer is now required:
Default.aspx
Default.aspx.designer.cs
Default.aspx.cs
The designer file is auto-generated, but you may need to "touch" each page to generate.

Any way to make Intellisense work, when opening a cs file that's not part of the project?

What we ideally need is, to know how Microsoft handles XAML generated code (Those *.g.cs files). If you goto a XAML code behind, intellisense will work even if the *.g.cs file is not part of the project!!
Context:
In a custom VS package, we need to have some logic to open a CS file (with out making it a part of the project) in the VS IDE, to allow the user to edit it.
We are hooking up the document to the Running document table and receiving the events like Saving, Close and all, using IVSRunningDocumentTable. Works good.
Now the problem is, when the document is opened, Intellisense can't work, for the simple reason that the opened document is not part of the project (sadly, we can't do that, we can't make it code behind).
Intellisense is driven by a memory cache of identifiers and types. These types are cached based on the project you are in and the references that project has. If the code file you are editing is not part of a project, Visual Studio would have to load every possible assembly and create intellisense data for each type in the entire .NET framework because it would have no way of knowing whether or not your code file required it.
I guess Visual Studio could load intellisense based on the content of the file but that is not the way it currently works.
Visual Assist X by Whole Tomato is an addin to VS I've been using for many years. It will give you Intellisense and more when you open it.

Categories