I needed to make a new page which was very similar to another so I simply copied it and renamed both the file and the class name within the code.
So far so good.
However, if I make a change to the markup, the designer file in the new page forgets the new class name and reverts to the old one causing compile errors.
It is easy enough to fix but is there some way of making the change stick rather than having to do this each time?
Also, should I have cloned the page a different way?
Well, I thought this was just a feature but when I ran the new page it routed to the old one.
On inspection, the problem was this line:
<%# Page Language="vb" AutoEventWireup="false" Codebehind="WibbleNew.aspx.vb" Inherits="Wibble"%>
I had changed the Codebehind section but not the Inherits, so it should have been:
<%# Page Language="vb" AutoEventWireup="false" Codebehind="WibbleNew.aspx.vb" Inherits="WibbleNew"%>
I did say it had been a while... :-/
You could put the common features in a master page and then just create separate pages for the two sets of differences.
There is a good intro to that here: http://www.w3schools.com/aspnet/aspnet_masterpages.asp
Related
I have a project I inherited on only one of the pages the break points are not being hit. They are not hollow, they are solid and look as if they are going to be hit when I run the code, but when the page loads (one of the break points) it does not break. Now I added a break point to a different page (onLoad) and it does it. I have never come across this before, does anyone one have any insight on this crazy visual studio behavior?
I have tried to clean and rebuild the project and still not working.
aspx page:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Screener.aspx.cs" Inherits="Screener.Screener" %>
.cs page:
namespace Screener
{
public partial class Screener : System.Web.UI.Page
One thing I just noticed, the code behind page is 1633 lines long, should that matter?
I just deleted the old page and re-created it and still nothing.
There is another way to force a breakpoint (in code)
Add the System.Diagnostic namespace to your code behind
add an additional line of code Debugger.Break();
This will force the debugger to break (if running) otherwise a dialog box will appear asking to debug. Should identify if this is an issue with visual studio caching something or the code that you wish to debug is not being called.
Do not forget to remove from code when done.
http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break(v=vs.110).aspx
You know how ASP.NET pages typically begin with a Page directive setting certain properties and behaviors for the page? Looks like this:
<%# Page Title="Contact Us" Language="C#" MasterPageFile="~/Site.master"
AutoEventWireup="true" CodeFile="ContactUs.aspx.cs" Inherits="ContactUs" %>
The whole list of currently available directives is here:
http://msdn.microsoft.com/en-us/library/t8syafc7.aspx
Does anyone know if it is possible to create new directives?
For example, I'm using reflection to do certain things with pages on the site and I decorate their class declarations with custom attributes. I'd like to know if it's possible to somehow do that even when there isn't a code behind or designer file to find such a class declaration, and all the scripts for the page are in the script tag that's run on the server side.
P.S. I'm aware that I could use the Page directive to set the base class and then also use it to set inherited properties. However, there can be 0 - n of these attributes, so that couldn't be done elegantly.
we are facing a strange issue. we have a (custom)file upload control in our page . which binds files to a grid view. say our page name is xxx.aspx. our custom file upload control works fine every where except xxx.aspx. when we attach files on xxx.aspx it does not show files in grid although grid view contains the attached file in it(on server side) but is not rendering on client side. (its out side of an update panel, so its not an ajax problem).
if we rename the page to something else, say "aaa.aspx", it starts working fine.
so there is something with the xxx.aspx.
what it could be ? any idea?
try checking your header on aspx and class on server side
cause when you just rename your asp page the code doesnt change itself so you have to rename also
like this
<%# Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false"
CodeFile="xxx.aspx.vb" Inherits="xxx" Title="Untitled Page" %>
and on your server side
Partial Class xxx
end class
get my point?
Is this invalid to put in an aspx file? I have some static aspx pages and I want to add a bit of C# to one of them. How can I do this?
I figured just adding
<%# Page Language="c#"%>
and then using <% %> to put a bit of C# goodness in there, but it says Syntax Error. with a blue wavy line over this code.
This happens whenever you change the Language attribute of the Page directive. Simply close the file in Visual Studio, and reopen it. The error will go away.
It's not entirely clear from your question, but are you adding multiple Page directives? You can only have one per .aspx file.
Otherwise what you've got there is valid. If your page works fine and VS is still showing it as an error, quit out of VS entirely and restart it.
In my WAP project, every .aspx's code-behind and designer share the same namespace. For example my Main.Master.cs and Main.designer.cs are both in the OurCompany.Web namespace by default.
When I go to another .aspx page and use the following, I get an "Ambiguous reference" error because it can't decide if I'm talking about my code-behind or designer file of that master page
<%# MasterType TypeName="OurCompany.Web.Main" %>
but by default this is the way VS creates .aspx pages so should I really care?
The designer files are all marked as "partial" classes so they don't get compiled into their own types.
My guess is that you really do have 2 classes called "OurCompany.Web.Main". A tool like Reflector would let you browser your DLLs so you could tell for sure.
This just happened to me, your problem is the JIT compilation creating temporary "copies" of your assemblies in a temp directory.
Make sure every namespace/partial class declaration is "tight", check for incorrect class names, wrong namespaces.
The problem "just went away" for me as well. Recreating or cleaning the solution will probably do it. Wish I could be more helpful but going cleaning up the source, both manually and with the right click menu probably helped.
I'm guessing you have a master page and a web form page with the same name on the code behind class. And this will prevent your site from working correctly (if it works at all).
I'd go through my aspx.cs files and looking for the class name main (find should work here). I bet you will find two files with the name. You will have to change one of them to something else. Just make sure you also change the Inherits in the .aspx page and the .designer.cs class name.