locked
CustomPages not working RRS feed

  • Question

  • User1432255915 posted

    Hi,

    I created an ASP.NET Dynamic Data Web Application

    I would like to customise the List page to display only some fields in the grid view for a particular table. That is what I have done:

    1 - Created a folder under CustomPages folder called tblUsers (my table name is tblUser and the entity set name is tblUsers)

    2 - I copied the List.aspx from the PageTemplates folder into the CustomPages/tblUsers I created.

    CustomPages/tblUsers/List.aspx

    However, the application does not compile any more. I think there is a conflict with the names in the file I copied. I get a lot of errors.

    Please can someone shed some light on how to fix this? I saw a talk by David where he justed copied the List.aspx to the new folder and everything just worked. Why this is not working for me?

    Error 1 The type 'MarsUsersAdmin.List' already contains a definition for 'table' C:\dev\MarsUsersAdmin\MarsUsersAdmin\DynamicData\CustomPages\tblUsers\List.aspx.cs 14 29 MarsUsersAdmin

    Error 2 Type 'MarsUsersAdmin.List' already defines a member called 'Page_Init' with the same parameter types C:\dev\MarsUsersAdmin\MarsUsersAdmin\DynamicData\CustomPages\tblUsers\List.aspx.cs 16 24 MarsUsersAdmin

    Error 3 The type 'MarsUsersAdmin.List' already contains a definition for 'headContent' C:\dev\MarsUsersAdmin\MarsUsersAdmin\DynamicData\CustomPages\tblUsers\List.aspx.designer.cs 18 61 MarsUsersAdmin

    Error 12 The type 'MarsUsersAdmin.List' already contains a definition for 'GridView1' C:\dev\MarsUsersAdmin\MarsUsersAdmin\DynamicData\CustomPages\tblUsers\List.aspx.designer.cs 34 62 MarsUsersAdmin

    Friday, February 3, 2012 11:07 AM

Answers

  • User-330204900 posted

    Simple solution Pallone, you need to change the namespace on the page you copied what I usually do is:

    in the .aspx page

    <%@ Page Language="C#" MasterPageFile="~/Site.master" CodeBehind="List.aspx.cs" Inherits="Northwind.TableName.List" %>
    

    in the .cs file

    namespace Northwind.TableName
    

    hope that helps, this is normal in any Web Application project and does not happen in Website project.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 3, 2012 11:20 AM
  • User1641955678 posted

    The problem is that you're trying to request the custom page directly (/DynamicData/CustomPages/tblUsers/List.aspx). Instead, the idea of Custom Pages is that you keep on making the same request as before you had the custom page, but you'll end up having it override the Page Template.

    e.g. here you probably want to request /tblUsers/List.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 4, 2012 2:24 AM
  • User1641955678 posted

    For the namespace conflict, yes, WAP vs Web Site is the difference. In WAPs, all the code behind sources get compiled in the same assembly, so you can't have conflict. In Sites, they each end up in separate assemblies, so it doesn't matter.

    For the 404 issue, please see my initial answer to this thread. We need to understand exactly what URL you requested.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 4, 2012 8:10 PM
  • User1641955678 posted

    WAP vs Web Site can be a difficult choice, as they have pros and cons. In WAP's, the courses get compiled in VS at design time, while in Web Sites, everything is compiled at runtime (and there is no 'bin' assembly). Check out this post which discusses many of the differences.

    For the 404, it's actually clear from the error message that you requested /DynamicData/CustomPages/tblUsers/List.aspx instead of going through the DD route, which is why you get this (those pages are not meant to be requested directly).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, February 5, 2012 8:05 PM
  • User-330204900 posted

    MarsUsersAdmin\MarsUsersAdmin\DynamicData\CustomPages\tblUsers\List.aspx

    this path should be

    ~/tblUsers/List.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 6, 2012 4:39 AM
  • User1641955678 posted

    Most likely, what happened is that you were on that page and hit Ctrl-F5 to run it, which causes VS to launch the browser directly on that page instead of going through the proper routes. MVC views have the same issue. It's unfortunate that we couldn't quite get VS to do the right thing here, but oh well! :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 6, 2012 12:57 PM

All replies

  • User-330204900 posted

    Simple solution Pallone, you need to change the namespace on the page you copied what I usually do is:

    in the .aspx page

    <%@ Page Language="C#" MasterPageFile="~/Site.master" CodeBehind="List.aspx.cs" Inherits="Northwind.TableName.List" %>
    

    in the .cs file

    namespace Northwind.TableName
    

    hope that helps, this is normal in any Web Application project and does not happen in Website project.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 3, 2012 11:20 AM
  • User1432255915 posted

    Hi sjnaughton,

    Thanks.

    This is strange because I have a demo where this is working and the namespace is the same in the page I copied.

    I will try to change the name and see what happens. By the way, do I have to use the table name or entity set name for the folder?

     

    Friday, February 3, 2012 12:47 PM
  • User1432255915 posted

    Hi,

    I have changed the namespace as you suggested but now I get a 404 error. This is how I changed it:

    tblUser = table name

    tblUsers = Entity Set name

    <%

    @ Page Language="C#" MasterPageFile="~/Site.master" CodeBehind="List.aspx.cs" Inherits="MarsUsersAdmin.tblUser.List"

    %>

     namespace MarsUsersAdmin.tblUser
    {
        public partial class List : System.Web.UI.Page
        { 

     What have I done wrong?

    Cheers

     

    Server Error in '/' Application.


    The resource cannot be found.

    Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

    Requested URL: /DynamicData/CustomPages/tblUsers/List.aspx


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272 <!-- [HttpException]: Path '/DynamicData/CustomPages/tblUsers/List.aspx' was not found. at System.Web.HttpNotFoundHandler.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) -->

    Friday, February 3, 2012 12:59 PM
  • User-330204900 posted

    the folder name should also be the plural name of the table the namespace dose not matter, it just has to be unique.

    Friday, February 3, 2012 1:13 PM
  • User1432255915 posted

    This is exactly what I did but it is still not working.

    MarsUsersAdmin\DynamicData\CustomPages\tblUsers\List.aspx

    Friday, February 3, 2012 1:30 PM
  • User1641955678 posted

    The problem is that you're trying to request the custom page directly (/DynamicData/CustomPages/tblUsers/List.aspx). Instead, the idea of Custom Pages is that you keep on making the same request as before you had the custom page, but you'll end up having it override the Page Template.

    e.g. here you probably want to request /tblUsers/List.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 4, 2012 2:24 AM
  • User1432255915 posted

    Hi David,

    I have not changed anytying in the application. I just followed your MIX08 talk and copied the List.aspx page to the CustomPages/tblUsers/List.aspx.

    However, after I do that the application does not build. I get a lot of namespaces conflict which you did not get in the talk.

    Could you please shed some light why this is happening to me?

    Cheers

    Claudio

     

     

    Saturday, February 4, 2012 3:34 PM
  • User1641955678 posted

    Claudio, I think we're talking about two unrelated things here. :)

    Your initial issue was caused by keeping the same namespace as Steve mentioned. I assumed this was resolved.

    My response was to the follow up 404 error.

    Saturday, February 4, 2012 3:57 PM
  • User1432255915 posted

    Hi David,

    yes, I changed the namespace as Steve mentioned and the application builds ok but then I get the 404 error as the file did not exists.

    I do not know how to fix this. Why DD is not able to find the new folder and file under the CustomPages folder?

    But in your MIX08 talk you did not have to change the namespace after copying the List.aspx file under the new folder and it just worked.

    I also have some sample code from another source and I have checked the List.aspx that he copied under the CustomPages/Companies folder and it works fine. He did not have to change the namespace at all.

    I was wondering if this caused because I am using a Web application and his demo uses a Web Site. Also I put my EF model under a folder called DAL.

    Cheers

    C

     

    Saturday, February 4, 2012 7:56 PM
  • User1641955678 posted

    For the namespace conflict, yes, WAP vs Web Site is the difference. In WAPs, all the code behind sources get compiled in the same assembly, so you can't have conflict. In Sites, they each end up in separate assemblies, so it doesn't matter.

    For the 404 issue, please see my initial answer to this thread. We need to understand exactly what URL you requested.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 4, 2012 8:10 PM
  • User-330204900 posted

    yes you will have issues if you move files between Web Application Project and Website projects, as there are a few differences between the files.

    Can you post the URL you are using to access hte custom page as we may have another issue :)

    Sunday, February 5, 2012 10:36 AM
  • User1432255915 posted

    Hi David, sjnaughton

    Thanks for your help.

    Ok, now I understand why I have to fix the namespace and in you MIX08 talk you did not.

    Could you please explain a bit more for completeness what the difference between having all the files in the same assembly WAP and not Web Site is?

    Does it mean that I can change individual aspx and code behind fies in Web sites and deploy them independently of the assembly but with WAP I have to always deploy the full assembly even if I change just one file? i.e. I have to compile the whole site even tough I change only one code behind file?

    As for the URL and 404 problem. I do not have the computer with me at the moment but will check it tomorrow and let you know.

    One thing I have noticed yesterday is that for some reason VS 2010 created 2 folders MarsUsersAdmin when I created the application

     MarsUsersAdmin\MarsUsersAdmin\DynamicData\CustomPages\tblUsers\List.aspx

    I have not changed the route at all. So I was wondering if this could be a problem for DD?

    Cheers

    C

    Sunday, February 5, 2012 5:34 PM
  • User1641955678 posted

    WAP vs Web Site can be a difficult choice, as they have pros and cons. In WAP's, the courses get compiled in VS at design time, while in Web Sites, everything is compiled at runtime (and there is no 'bin' assembly). Check out this post which discusses many of the differences.

    For the 404, it's actually clear from the error message that you requested /DynamicData/CustomPages/tblUsers/List.aspx instead of going through the DD route, which is why you get this (those pages are not meant to be requested directly).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, February 5, 2012 8:05 PM
  • User-330204900 posted

    MarsUsersAdmin\MarsUsersAdmin\DynamicData\CustomPages\tblUsers\List.aspx

    this path should be

    ~/tblUsers/List.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 6, 2012 4:39 AM
  • User1432255915 posted

    Hi David, sjnaughton,

    Thanks again.

    For some reason I run the application this mornning and the 404 error is gone.

    I do not understand what has happened but I think that setting the default.aspx as the starting page might have helped.

    I really appreciate your sharing you knwoledge with us

    Cheers

    C

     

    Monday, February 6, 2012 7:00 AM
  • User1641955678 posted

    Most likely, what happened is that you were on that page and hit Ctrl-F5 to run it, which causes VS to launch the browser directly on that page instead of going through the proper routes. MVC views have the same issue. It's unfortunate that we couldn't quite get VS to do the right thing here, but oh well! :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 6, 2012 12:57 PM
  • User1432255915 posted

    thanks David

    Monday, February 6, 2012 3:29 PM