Changes in a copy of the master aspx file not being seen - c#

I am attempting to make some changes to an asp.net website at short notice. In order to work on these without affecting the live site I have made a test copy of both the index.aspx file and the Site_Main.Master file. I have done this in the past without problems (I think, though I am starting to question myself).
The copies of the files are named index_test.aspx and Site_Main_test.Master respectively.
In the index_test.aspx file I have updated the MasterPageFile field accordingly...
<%# Page Language="C#" Debug="True"
MasterPageFile="~/MasterPages/Site_Main_test.Master"
AutoEventWireup="true"
CodeBehind="index.aspx.cs"
Inherits="EWS.L2B.Web.Index" %>
When I visit index_test.aspx in the browser it works fine, telling me I have succesfully set up the conditions to work on test versions of the files.
The problem is when I start to make changes in Site_Main_test.Master it doesn't seem to be 'seeing' those changes.
So in order to debug this issue, I put a simple Response.Write("<!-- Test -->"); near the top of the Master file. No sign of that in the page response when visiting index_test.aspx in the browser.
Scratching my head, I decide to risk putting the same in the original Site_Main.Master file, and load the index.aspx in the browser. The <!-- Test --> comment shows up!
I am fully aware this is probably an unrecommended way of working on an asp.net website but I don't have time to figure out another way to do this.
I can't figure out why changes to the original Master file are immediately apparent, whereas changes in the test copies seem to be being ignored. Any help would be appreciated.
(As another troubleshooting test I deliberately broke Site_Main_test.Master, which does generate an error when I visit index_test.aspx, which tells me it is at least picking up the copy of the Master file)

Related

Adding '/[x]' to any aspx page still shows the page, expected 404

no idea where to start on this one, but here goes. if i've missed an answer somewhere is becuase i don't know how to search for the error.
take a aspx page i.e. www.example.com/about when testing i have found (accidently i must say) that adding /anything i.e. www.example.com/about/eduhdbbw still returns the www.example.com/about page (assuming www.example.com/about/eduhdbbw doesn't exist). i would expect a 404 in this situation but i don't really know how it is routing to the original page.
fyi i'm using VS 2017 community with iis and asp.net webforms with c# and the error occurs in vs and compiled in iis. if any other info is needed please ask.
Edit: the about page does indeed show .aspx in the browser url. Also i am using a blank webform template, so it didn't come with anything pre-installed and i've not written and url re-write.
Pathinfo sound like it might be something but would this affect a project with just basic aspx and code behind, amd basically no other dependancy?
Also for now i am just using absolutepath to compare the page name and sending to 404 if it doesn't math; but it seems like a sloppy solution to have on every page...

Could a Web.UI.Page object (C#) correspond to a .html file, rather than a .aspx file?

I was checking the System.Web.UI.Page class methods and instantiation examples listed here: https://msdn.microsoft.com/en-us/library/system.web.ui.page(v=vs.110).aspx
In this case, the front-end file is an .aspx file and is linked to the back-end .cs file via this meta header:
<%# Page Language="C#" CodeFile="pageexample.aspx.cs" Inherits="MyCodeBehindCS" %>
Could a Page object also be tied to a pure .html file? If yes, then how are they tied to each other?
You cannot produce a page ends with "html" as a result, because the IIS have to know what kind of page it's dealing with, in order to follow the .Net life-cycle.
However, you can consider the Page is already produces a pure HTML file, since it's the only code that the browsers can understand. If you want to have the same on developer's view, just don't use the benefits of .aspx objects.
But of course, you can find workarounds too. You can create an HTML file with Javascript codes which triggers the .aspx pages needed, and puts the results. By the look of the user, it's all will be looking like an HTML file. (And Javascript ofcourse)
One option, though keep in mind you're technically fooling IIS in this instance:
Open IIS Manager and select the target website.
Open HandlerMappings applet
Copy the mapping where Path is *.aspx into a duplicate where path is *.html.
Then, add a handler in your config to tell IIS what to do with this file type:
<httpHandlers>
<add path="*.html" verb="*" type="System.Web.UI.PageHandlerFactory" />
</httpHandlers>
Note: If you have HTML pages without server-side code in them, this could end up being troublesome. You may be better off just exempting extensions altogether and look at using routing.

Issues with code behind generation

For some odd reason, I can't get my page's code behind to generate, the file has been created but none of the controls seem to be getting generated in..
There are no warnings/errors coming from VS when I am trying to generate this file, this has worked in the past but suddenly it stopped working and as far as I know nothing has changed apart from I have installed .NET Demon which I have tried disabling fully but this doesn't appear to change it.
I have spent a good few hours looking into this issue and all I have found in terms of solutions is to delete the .designer.cs file and then converting the .aspx file to a web application but this does not fix my issue. I have also tried to recreate the page but no luck either, I will put below a few bits of code that may help.
Generated file namespace:
namespace Web.admin.reports {
<%# Page Language="C#" Inherits="Web.admin.reports.productpromotionsummary" Title="Promotions Summary" CodeBehind="~/admin/reports/productpromotionsummary.aspx.cs" AutoEventWireup="True" %
If you need anymore information please feel free to ask

GridView to Excel ASPX in SharePoint

I have an ASPX file which I am running in SharePoint that has a GridView which I am attempting to export into an excel spreadsheet. I know the code I have for the export is correct; however, I am getting this error:
RegisterForEventValidation can only be called during Render();
I have done some research and have found a solution, which might work with normal ASPX pages created in VS with a CS code behind class, which is setting the EnableEventValidation to false, and I am getting a Parser error when I attempt to use this solution on my ASPX page.
<%# Page Language="C#" AutoEventWireup="true" EnableEventValidation = "false"%>
Is there any other way to allow this, or any other workaround to my problem using just the ASPX page without the code behind? All of my C# code is within the head and has to be in order for me to run it in my SharePoint environment. 12 hive storage of the CS class is not an option for me. Also, I am not wanting to change anything in my web.config folder if possible.
Thanks
Try creating it as a Web Part - this is the more common approach for this type of scenario in SharePoint.
In SharePoint, all customized pages are run through the Safe Mode Parser which prohibits inline code. Also, this parser does not allow adding controls to pages which have not been marked as "safe".
To get around your issue, you might want to look at "Application Pages" which are added to the \LAYOUTS directory. They reference the master page and can have inline code, but they can't be customized. They are compiled into a single assembly DLL:
Creating an Application Page in Windows SharePoint Services 3.0

Broken link between aspx and aspx.cs files

I've had the same problem a couple of times with different ASPX pages after renaming them and I am surprised that I can't find someone else with the same problem on stackoverflow.
When I run my ASP.NET C# project, the debugger gives me a message like this one.
Error 5 The name 'txtTitle' does not exist in the current context
It seems that the aspx and aspx.cs files at no longer bound. The only fix I have found for this is to recreate the page and copy/paste my code.
Any idea how to fix this without recreating the whole thing?
Thanks
The code file contains a partial class that is referenced in the ASPX header declaration. Both file name and the actual class in the ASPX header have to match for this to work.
<%# Page Title="TestPage" Language="C#" AutoEventWireup="true" CodeFile="TestPage.aspx.cs" Inherits="TestPage" %>
In your case probably the class name does not match. Check if the class name in the codebehind .cs file matches the name after Inherits.
The concept of partial classes used in ASP.NET is detailed here.
I am surprised at this occurring I regularly rename Silverlight user controls with no harmful side-effects.
Are all of the references to classes being renamed in the aspx page and code behind ?
You might try using this util to relink them.
This can also be caused by the whatever.aspx.designer.vb file being dependent upon whatever.aspx.vb instead of whatever.aspx. If this is the case, it should show incorrectly in the file tree when you expand the group of files in Visual Studio. To fix it, simply exclude the affected files from the project and then re-include them - the faulty project config file should be regenerated and it should now work correctly.
(Same theory for C#.)
I've had the same problem and noticed that sometimes, but not always, the CodeFile setting in the .aspx page is not updated when the class is changed. If this is the same problem you have, you can change it manually:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="MyClass.aspx.cs" Inherits="MyClass" %>
^^^^^^^

Categories

Resources