How to duplicate a master page in asp.net - c#

I'm trying to skin a 3rd party asp.net application and don't boast to have any knowledge with MS web technologies.
One page design has a considerably different underlying html structure that can't be achieved with pure css so I need a new master file for this page.
I've naively duplicated a file called Main.Master renamed it Login.Master and changed the reference in the Page file that extends Main.Master to Extend the new master page file, e.g:
<%# Page Language="C#" MasterPageFile="~/Login.Master" EnableViewState="true"
AutoEventWireup="true" Codebehind="Login.aspx.cs" Inherits="xxx.login"
Culture="auto" meta:resourcekey="PageResource1" UICulture="auto" %>
In Login Master I've not changed a thing, as all the logic should be identical, I just want to change the structure of the HTML.
With the small change mentioned above I get several parser errors along the lines of:
Parser Error Message: The resource object with key 'somekey' was not found.
When I delete the reference to said error, it causes a new parser error further down, and so on and so forth.
I've also tried not having a master page for the page in question but that throws up a whole new collection of errors.
To make things worse, it's on a remote server and I don't have access to visual studio so would prefer a solution that wouldn't require compilation if at all possible.

Related

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

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)

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.

Where Controls Declarations in a website project are put

I have website i cant access the controls in the code-behind
i drag controls and add them to ASPX file and when i try to access them i cant.
i tried opening the website using:
Visual Studio 2012
Visual Studio 2010
when i even double click on a button it creates its event in the code behind but i still cant access the control!
there is no designer.cs file since this is a web site any idea how to fix it ?
If memory serves, the markup is the designer for a page that lacks a designer file. You can observe this behavior in classic ASP pages that have been ported to .NET.
The compiler simply parses the page, looking for a tag that includes runat="server" and generates a server-side control for it. If there's no ID, one is generated for it. Further, if AutoEventWireup="true" is set at the page level, the events will be automatically connected to these controls, as if by magic. It's all just compiler voodoo, if you ask me, but rather convenient compiler voodoo.
But that's an educated guess, based on experience, and I'm sure someone with far more experience with ASP.NET internals can provide more riveting details. (Jon Skeet, et al.)
Make sure your .aspx file specifies its codebehind file:
<%# Page Title="" Language="C#" CodeFile="YourPage.aspx.cs" Inherits="Content_YourPage" %>
If it is a website then websites don't have designer.
But if you need the designer's then try to convert it to web application

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