Is it possible to have code files in a seperate folder than the aspx files? RRS feed

  • Question

  • Hi there,

    Let me know if there is a better forum for this.

    I think the answer to this is likely no, but hoping there's a way that will save me a lot of tedious work.

     In our ASP.NET solution, we have the following structure in the solution:

    • ../codebehind/<cs files>
    • ../FolderA/<ASPX files>
    • ../FolderB/<ASPX files>

    Both the FolderA and FolderB folders contain almost the same aspx files, but layout is slightly different. However, they both reference the same file as specified by the CodeFile attribute on each page page directive.  The code itself has logic to differentiate between both paths. 

    As we're working on upgrading our site to .NET 4.5, we'd also like to get this project to build (for the long overdue goodness of being able to catch issues upstream in the development process).

    Any recommendations on how to go about this?

    Would my best bet be to potentially move everything into the APP_CODE folder?  

    If I do have to move the CS files to the same folder as the ASPX files, is there anyway to set the project up so that I will not have to maintain 2 seperate copies of the same CS file, under FolderA and FolderB?  


    • Edited by KeyurP Tuesday, April 16, 2013 9:42 PM
    • Moved by Lisa Zhu Thursday, April 18, 2013 7:17 AM not C# specific
    Tuesday, April 16, 2013 8:39 PM


All replies

  • If you updated the directive at the top you should be fine.

    <%@ Page Title="" Language="C#" MasterPageFile="" AutoEventWireup="true" CodeBehind="shared.cs" Inherits="" %>

    When you try to run the site what error(s) are you getting when trying to load these pages?

    Although this can be done I would recommend that each page has its own click event methods that calls a class with the logic.  Each page may have similar control names or different ones that may get confused during the life cycle of the page.

    • Edited by sdprest Tuesday, April 16, 2013 11:07 PM added last sentance
    Tuesday, April 16, 2013 11:03 PM
  • Hi KeyurP,

    Thank you for visiting the MSDN forum. I’m afraid that it is not the correct forum about this issue. I am moving your question to the moderator forum ("Where is the forum for..?"). The owner of the forum will direct you to a right forum.

    Thanks for your understanding.


    Lisa Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Edited by Lisa Zhu Thursday, April 18, 2013 7:17 AM
    Thursday, April 18, 2013 7:16 AM
  • Hi Keyur,

    Please try asking it at http://forums.asp.net/.



    • Proposed as answer by Just Karl Thursday, April 18, 2013 1:39 PM
    • Marked as answer by Just Karl Friday, April 26, 2013 3:31 PM
    Thursday, April 18, 2013 10:45 AM