locked
Partial classes RRS feed

  • Question

  • User41324886 posted

    well, i have an an aspx page called Page.aspx with a code file "Page.aspx.vb" and i want to add a second code file to split my code through several files .

    Is this possible ? and if yes, could i access the controls of Page.aspx from my second code file ? (I'm using .net v 2)

     Any help would be very appreciated

     Best regards

    Monday, June 11, 2007 10:58 AM

Answers

  • User139975600 posted

    I have been able to create the separate document with the partial class name, but the methods and fields aren't usable... The problem I am finding is that using partial classes for web-page code-behind files is that

    1. It violates the "same assembly" rule for partial classes (adding a class.vb file expects to be placed in the App_Code folder, and will compile into a DLL that doesn't also contain the original Page.aspx.vb content...

    2. The codebehind property of the Page.aspx file specifies the particular codebehind file (Page.aspx.vb) but doesn't allow for a second codebehind file.

    Partial classes work well enough in class files, but not really in codebehinds (from all that I have experienced).

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 11, 2007 11:58 AM
  • User-319574463 posted

     You could try to tame the size using #Region .... #EndRegion (or #End Region in VB.NET) - I have brought 10,000 line modules into line that way.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 11, 2007 3:32 PM

All replies

  • User-319574463 posted

     You could, provided the namespace (if any) and class were the same. However why do you need to do that? I have split out parts of a class library for various purposes (such as the minor part that need to be updated on a new project.)

    Monday, June 11, 2007 11:20 AM
  • User41324886 posted

    well, i want to split my code file through several files to organize my code, for example one file to load the need data, an another to hold the event handlers and properties ... (instead of having hundreds of code lines in one file)

     

    So if it's possible, how could i do so. i've tried to add a class that have the same name as my code file class and i marked it as partial, but i couldn't access web controls in my aspx page...

    Please help

    Monday, June 11, 2007 11:40 AM
  • User139975600 posted

    I have been able to create the separate document with the partial class name, but the methods and fields aren't usable... The problem I am finding is that using partial classes for web-page code-behind files is that

    1. It violates the "same assembly" rule for partial classes (adding a class.vb file expects to be placed in the App_Code folder, and will compile into a DLL that doesn't also contain the original Page.aspx.vb content...

    2. The codebehind property of the Page.aspx file specifies the particular codebehind file (Page.aspx.vb) but doesn't allow for a second codebehind file.

    Partial classes work well enough in class files, but not really in codebehinds (from all that I have experienced).

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 11, 2007 11:58 AM
  • User41324886 posted

    Well, this is what i've noticed, but Mr. TATWORTH  said i could, maybe he got some workarround to this issue...

    Could you share with us Mr TATWORTH ?

    Monday, June 11, 2007 12:36 PM
  • User-319574463 posted

    >Well, this is what I've noticed, but Mr. TATWORTH  said i could, maybe he got some work around to this issue...
    Regrettably no - however I would like to know why you need to split the code behind?

    Monday, June 11, 2007 12:52 PM
  • User-1630302068 posted

    My gut reaction is "Make your page smaller".  Maybe there are sections of it that you can break out into UserControls & MasterPages?  I've just never run into a situation which would really call for splitting up the code like your proposing and it seems like there should be a better way to organize your code.

    Monday, June 11, 2007 1:02 PM
  • User41324886 posted
    Well, i do use master pages and  user controls, but  still got more than 3000 lines of code, i'm just maintaing this "strange" application. i know this is duo to a bad design from begining. And my managers refuse to redisigne the interface, so i'm looking for a quick workarroud so that i can end up with a more maintainable code...  
    Monday, June 11, 2007 2:44 PM
  • User-319574463 posted

     You could try to tame the size using #Region .... #EndRegion (or #End Region in VB.NET) - I have brought 10,000 line modules into line that way.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 11, 2007 3:32 PM
  • User41324886 posted

    Well, this is what i'm doing actually, and its simply okey :)

    Thx all for your help

    Wednesday, June 13, 2007 5:07 AM