Two parts to this question:
1 - when a razor page file (example.cshtml) is updated, will the ASP.NET Core auto compile that file?
2- when a razor page code-behind file (example.cshtml.cs) is updated, will the ASP.NET Core auto compile that file?
I have many web forms that require maintenance and do not want to have to recompile and publish the whole site files every time a single page is updated if we port to Razor Pages.
That depends on your development environment. Assuming you are using Visual Studio as your IDE, usually yes, you will be both able to update your views and code-behind files during a debugging session, if you are running a debug session, and using a debug build (personally, I have never tried to do this in a non-debug build, as I actually see no point in doing so).
I say "usually" because there are some situations which the IDE is not able to update the code which runs behind your app's deployment. Most of the times, if you just alter the code of method bodies in your code-behind files or change some things at your view, things will work smoothly (although you might notice some delay at the first time you reload a page that has been affected by your changes: this is because the IDE is updating your deployment behind the scenes when you reload that page).
However, if you try to do some more complicated things, like editting the signature of methods, declaring new properties in one of your classes, or injecting new stuff in your views, the development environment might have some trouble to update your deploy. Check the screenshot below for a message given by Visual Studio Community 2017 when I try to add a new parameter to a method of a controller I have in one of my projects: the IDE warns me that it won't be able to upload my deployment in the server, and thus my changes won't be correctly reflected during my current debug.
Also, one thing to keep in mind is that Visual Studio mostly will only allow you to make editions to your code when you pause the debug session. Code will be in read-only state if the application is currently running.
I am building a personal website using asp.NET's webforms in visual studio 2013 express for web and am following this tutorial:
http://www.asp.net/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/introduction-and-overview
My page is structured exactly the same as in the website, I have changed some minor stuff to make it my own but the structure in terms of the C# classes and how the interact with the HTML are exactly the same.
I got to section 5 of the tutorial "Display Data Items and Details" and everything was working fine. I've used git a lot in the past so I decided to create a repository for this project so I can access it at work if I feel like.
Suddenly now when I make changes to the C# classes it won't build. It's even stranger because I if I make a change on an HTML file the change is built. In section 3 of the tutorial we learnt how to make the 'product' classes which are displayed on the products page. If I want to change one of the product names for example, when I build the change is not there. Simultaneously I went and changed some info in the HTML for the contact page, IT CHANGES when I build. Why wont the C# changes take effect when I build any more?
I am relatively new to both asp.NET and visual studio. The HTML changes when I build and the C# does not. When I change either I can see in solution explorer that there is a red tick for pending changes. Why would only the HTML pending change be included in the build and not the C#? How do I ensure that the build is actually building the version I see in my editor window?
EDIT
I do not know if I found the original cause but I found a solution/workaround. I realized that the classes mentioned above were grabbed by the html page from the page's database. The .mdf file for the solution was not being rebuilt whenever I cleaned and built so I physically deleted it and rebuilt the solution and voilla my C# changes occurred. I am still fairly new to this whole thing, can someone explain what the .mdf file does and why it wasn't being rebuilt?
Check your .cs files properties on the properties window in visual studio to make sure their Build Action is set to "Compile", Things that are not set to "Compile" do not get compiled. How MSBuild treats project items depends entirely on their build action. CS files default to "Compile" when you make them, but if you changed them yourself that would be why it doesn't update. Also CS files placed in the App_Start folder default to "Content" and they are compiled by ASP.Net when the Application Starts, so if you changed something in App_Start you need to reset the site.
Not exactly sure what is the problem, but I would do a right mouse click on the solution in Solution Explorer->Clean Solution, then do another build and see if that helps.
After migrating a website project I am facing a strange behaviour of Visual Studio Dynamic compilation. Whenever I modify an aspx file or master page and save it, the modification is visible instantly in my debug browser, I just need to refresh the page. However when I make a modification on an ascx file and save it: no change is visible when I refresh the browser. The modification is only visible if I restart IIS or recompile the whole project.
Does anyone have an idea on whatever might be causing the dynamic compilation not to work properly with ascx when it works fine with aspx and master pages?
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.
Ok, so, my visual studio is broken. I say this NOT prematurely, as it was my first response to see where I had messed up in my code. When I add controls to the page I can't reference all of them in the code behind. Some of them I can, it seems that the first few I put on a page work, then it just stops.
I first thought it may be the type of control as initially I was trying to reference a repeater inside an update panel. I know I am correctly referencing the code behind in my aspx page. But just in case it was a screw up on my part I started to recreate the page from scratch and this time got a few more controls down before VS stopped recognizing my controls.
After creating my page twice and getting stuck I thought maybe it was still the type of controls. I created a new page and just threw some labels on it. No dice, build fails when referencing the control from the code behind.
In a possibly unrelated note when I switch to the dreaded "design" mode of the aspx pages VS 2008 errors out and restarts.
I have already put a trouble ticket in to Microsoft. I uninstalled all add-ins, I reinstalled visual studio.
Anyone that wants to see my code just ask, but I am using the straight WYSIWYG visual studio "new aspx page" nothing fancy.
I doubt anyone has run into this, but have you?
Has anyone had success trouble shooting these things with Microsoft? Any way to expedite this ticket without paying??? I have been talking to a rep from Microsoft for days with no luck yet and I am dead in the water.
Jon Limjap: I edited the title to both make it clear and descriptive and make sure that nobody sees it as offensive. "Foo-barred" doesn't exactly constitute a proper question title, although your question is clearly a valid one.
The above fix (deleting the temp files) did not work for me. I had to delete the PageName.aspx.designer.cs file, then right-click my page, and choose "Convert to Web Application" from the context menu.
When Visual Studio attempted to rebuild the designer file, it encountered (and revealed to me) the source of the problem. In my case, VS had lost a reference to a DLL needed by one of the controls on my page, so I had to clean out the generated bin folders in my project.
try clearing your local VS cache. find your project and delete the folder. the folder is created by VS for what reason I honestly don't understand. but I've had several occasions where clearing it and doing a re-build fixes things... hope this is all that you need as well.
here
%Temp%\VWDWebCache
and possibly here
%LocalAppData%\Microsoft\WebsiteCache
Is the control that you are trying to reference inside of the repeater?
If so then you need to look them up using the FindControl method.
For example for:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server">stest</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
You would need to do this to reference it:
LinkButton lb = Repeater1.FindControl("LinkButton1");
In my case, I was working with some old web site code, which I converted to a VS2008 solution. I encountered this same problem.
For me, the fix was to right-click the Web Sites project in the Solution Explorer and select Convert to Web Application. This created designer.cs files for all pages, which did not yet have these files before.
you will also find .net temp files which are safe to delete here:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
I observed this happens because of missing .designer.cs file. Following fixed this issue in my case (basically I had these files copied from VS 2005 web project to VS 2010 project): Right Click on .aspx file and select menu "Convert to Web site", this will create .designer.cs file and then it should work file.
In my case new asp controls I added to an existing were not being detected.
What worked for me was forcing a recompile by renaming an existing control to break the build eg: changing <asp:TextBox ID="txtTitle" runat="server" /> to <asp:TextBox ID="txtTitle2" runat="server" />
When I corrected the ID and rebuilt a new designer file was generated with the corrected ID and new controls.
right click on project name and select "Clean". then, check your bin folder if it has any dll remaining. if so, delete it. that´s it. just rebuild and every thing will work fine.
This can also happen if the Inherits property on the source page doesn't match the class name in the code behind. Generally speaking, this would probably only happen if you copy/pasted a .ascx/.aspx file and forgot to update it.
Example:
<%# Control AutoEventWireup="false" CodeBehind="myControl.ascx.vb" Inherits="myProject.myWrongControl" %>
The the code behind class:
Partial Public Class myControl
we cannot change the code when the application is running .To do so first click on the stop button on the top which will halt your application .now click on the button in design mode ,it will insert the code in .aspx.cs file ,then write the code in it
Check out your aspx file on errors, once I've faced with that problem
I had this happen a few times and it happened again today for a new reason. I normally run my project through IIS but needed to run it locally to debug. I normally run on port 80 in IIS and 81 in debug, but I had some settings in the web.config that used 80 so I just killed the site in IIS and switched the website to port 80 in the project settings. For whatever reason, this messed everything up and created the problem described in the OP. I started trying things one by one, including all the advice mentioned here, but switching the port back to 81 in the project settings is what ended up working.
For me, deleting/renaming the files in the following location worked:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\myvirtualwebsite\e331e0a9
Just to add my two cents with this problem.
The only thing from all the above that worked for me was the "Clean" and then delete anything left in the bin folder. Rebuild and all controls started working then.
FYI...I was having this problem too and I ended up fixing it by deleting the existing .designer.vb file, right-clicking on the project and choosing Convert to Web Application. It then showed the real "error" that was causing the GUI to crap itself. Turned out I had used the same name for 2 other labels but that wasn't being shown in the error list window. Once I renamed one of the 2 other labels it built fine and stopped giving me trouble.
You have to add
runat="server"
to each element in your page.