Results 1 to 7 of 7

Thread: ASP Classic INCLUDE FILE Equivalent in ASP.NETs ASPX.vb or ASPX.cs

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2017
    Posts
    37

    ASP Classic INCLUDE FILE Equivalent in ASP.NETs ASPX.vb or ASPX.cs

    Hello All.

    ASP.NET (VB or C# Question referencing the ASPX.vb or ASPX.cs files)

    In Classic ASP we use INCLUDE FILE to place code in another page and reference the code in other pages.
    This helps to keep things much more organized and helpful in adding in new elements as we know what page to go to, instead of what LINE NUMBER to go to.

    In ASP.NET, is there such a thing?
    Can we do this within the aspx.vb or aspx.cs file?
    Or do we just have to deal with large coded files only?

    I was given a suggestion, which I am not certain about, which is client-side rendering. (Will have to research it to see if it is something that would work in my scenario.)

    Currently, my file is at 2351 lines, which is not many compared to other projects.
    However, it would be nice to break the page up into segments, to make it easier to work with.

    Any ideas?
    Thanks.

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: ASP Classic INCLUDE FILE Equivalent in ASP.NETs ASPX.vb or ASPX.cs

    If you are looking at making reusable UI components then aspx has the concept of user controls https://learn.microsoft.com/en-us/do...ui.usercontrol which serve a similar purpose.

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2017
    Posts
    37

    Re: ASP Classic INCLUDE FILE Equivalent in ASP.NETs ASPX.vb or ASPX.cs

    Hello, PlausiblyDamp.
    Not sure that is what I am looking for.
    Are you familiar with ASP Classic Include files?

    Pretty much.

    <%
    'Your code is here. With 1000 lines.
    %>

    You break the code up into segments like this.

    Code:
    <%
    'Code with 250 lines
    %>
    <!--#include file="page1.asp"-->
    <%
    'Code with 250 lines
    %>
    <!--#include file="page2.asp"-->
    <%
    'This ends the page
    %>
    Now, with that,

  4. #4
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: ASP Classic INCLUDE FILE Equivalent in ASP.NETs ASPX.vb or ASPX.cs

    That isn't really how you do things in aspx, either write the reusable code in a class or module, or use ascx if it is reusable UI.

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2017
    Posts
    37

    Re: ASP Classic INCLUDE FILE Equivalent in ASP.NETs ASPX.vb or ASPX.cs

    Over a year later, but wanted to respond.
    It does work that way on the FrontEnd, just not in the CodeBehind.
    But the FrontEnd works the same way as Classic.

  6. #6
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,370

    Re: ASP Classic INCLUDE FILE Equivalent in ASP.NETs ASPX.vb or ASPX.cs

    Since we're responding to older posts, I'll chime in with my $0.02.

    You could use the concept of partials, but you need to leverage ASP.NET MVC. I used to do this all the time at my previous job where we'd have a SPA per feature. For example, if you're on the Admin > Users route then you'd have these files setup:
    • Index.cshtml: represented your layout
    • _search.cshtml: partial representing only the "search" page
    • _view.cshtml: partial containing a tab that held the form for updates and other tabs
    • _form.cshtml: partial representing only the "form" used in upserts
    • _roles.cshtml: partial representing a tab item in the _view partial
    • _change-password.cshtml: partial representing a tab item in the _view partial


    We then held the logic for each feature within each code file and Index.cshtml would essentially handle the SPA routing so that /Admin/Users#create would show in the _form.cshtml template, /Admin/Users#view?id=1&tab=roles would show in the _view and the _roles partials.

    While we did this in the context of reusable components, similar to what PlausiblyDamp was saying, theoretically you could just have:
    • Index.cshtml
    • _page1.cshtml
    • _page2.cshtml
    • _page3.cshtml
    • ...


    And then just inject all of your pages in Index.cshtml via:
    Code:
    <partial name="_page1" />
    <partial name="_page2" />
    <partial name="_page3" />
    <!-- etc... -->
    Though I'd say that's more of a code smell if you're needing to bust chunks of code out into different pages like that.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2017
    Posts
    37

    Re: ASP Classic INCLUDE FILE Equivalent in ASP.NETs ASPX.vb or ASPX.cs

    After over a year, I have found an answer to this lingering question of mine.
    It is called Classes.
    In ASP.NET, you create a Class and reference that Class within your other pages.
    I am still learning and do not know enough to talk about it.
    But I am using it right now in the new Upload script that I have had for years, with all 2,703 lines of code on one page.
    I know that does not seem like much to most, but to me, I like being organized in my coding, and having many lines in one file is too much.
    I have split it into many different Classes and referenced the classes.
    Some I can do on my own, and others I have to get assistance from wherever I can find it.

    For all those who are coming over from Classic ASP to ASP.NET
    Whether you are a VB or C#, it is the same thing.
    Instead of <!--include file="MyFile.asp"-->
    You will create a Class.
    VB

    Code:
    Public Class Customer
    End Class
    C#

    Code:
    public class Car
    {
    }

    It is nice to finally know this, and I truly wish I had given it the time it deserved when I was first told about it about 8-10 years ago.
    But I was stuck in my ways and did not want to learn anything new, and now today, I have no other choice.
    Clean and fast code requires doing it right.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width