Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7698943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:21:42+00:00 2026-05-31T22:21:42+00:00

How .aspx and aspx.cs file is being compiled? will it be two assemblies or

  • 0

How .aspx and aspx.cs file is being compiled? will it be two assemblies or both these files combined one and will be created as one assembly? Does any hierarchy/inheritance it follows? .aspx is being created as an corresponding C# code file (only then we could create an assembly right? correct me if i am wrong!) as one in windows form designer.cs file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:21:43+00:00Added an answer on May 31, 2026 at 10:21 pm

    It depends on the project type. With ASP .Net you can create two kind of projects: Web Application Project and Web Site Project..

    How .aspx and aspx.cs file is being compiled?

    With Web Application project you compile the code behind of the aspx files, user controls and other code found in this project into one single dll and deploy it on server.

    With Web Site Project you simply copy the source code on the server and ASP .Net will handle the compilation for you. The Web Site Project holds the source code of custom classes in App_Code folder (you’ll have to read more about these on that link)

    Will it be two assemblies or both these files combined one and will be created as one assembly?

    In none of these cases, the code found in the aspx, ascx files is not compiled by you (using Visual Studio, etc). ASP .Net parses these files and creates a dll stored in its temp folder. The “aspx, ascx” dlls (it can be more than a single one though) are different files than the one created by you with Visual Studio (and I believe is different than the one created from App_Code folder, since that code can’t access code found in the pages).

    Does any hierarchy/inheritance it follows?

    Yes. When a page is parsed and compiled, that generated class will inherit the one named at “Inherits” attribute, found at @Page directive.

    <%@ Page Language="C#" CodeBehind="Default.aspx.cs" 
             Inherits="WebApplication1._Default" %>
    

    ASP .Net parses Default.aspx file and generates a class which inherits WebApplication1._Default

    public class default_aspx : global::WebApplication1._Default
    {
    
    }
    

    Giving the fact that the generated class from markup inherits a class written by us (usually the one in the code behind, the aspx.cs file), we’re free to use its members or methods.

    The following method is a method of the _Default class:

     protected string ToUpper(string source)
            {
                return source.ToUpper();
            }
    

    Then in markup we can call:

    <form id="form1" runat="server">
      <%= ToUpper("Microsoft") %>
    </form>
    

    We can even write in markup something like:

    <% SomeValue = 1; %>
    <%= SomeValue %>
    

    Where SomeValue it’s at least a protected property of the _Default class.

    We’re free to declare members and write server code in the markup also:

    <head runat="server">
    
        <script runat="server" language="C#">
            private int someCounter = 10;
        </script>
    
    </head>
    <body>
        <% for (var i = 0; i < someCounter; i++)
           { %>
            <p>
                Paragraph number:<%= i %>
           </p>
        <% } %>
    </body>
    </html>
    

    Here I declare a someCounter field and use it to write 10 paragraphs. Of course this is not the recommended way to do such things. Since someCounter is a member of the generated class, this is not accessible in code behind.

    There is another huge (and more real) advantage of this architecture. Suppose some pages in the web site are kind static (about.aspx, privacy.aspx, etc), they use same Master page. The code behind in this pages doesn’t change. This means we can create other pages and deploy them without doing another compilation of the code behind (this aspect applies to Web Application Projects). Also, before going live, we might allow only one person to see these pages. So to achieve this we create a PreviewPage class

    public PreviewPage: System.Web.Page
    {
         public  PreviewPage()
         {
              this.Load += (o, e) => {
                   // code here to see if the authenticated user has the right to see the page
                  // if not, redirect the user to another page 
              }
         }
    }
    

    And change the Inherits value:

    <%@ Page Language="C#" Inherits="WebApplication1.PreviewPage" %>
    

    aspx is being created as an corresponding C# code file

    The Language attribute in the @Page directive dictates what language is used to compile the aspx/ascx file. So you can actually use VB.Net in the aspx file and to compile the website with C# compiler.

    This being another compilation, different than the one Visual Studio does, it is made with different options. This is why in web.config there are options to set the compilationMode to Debug/Release and also to instruct the compiler to use the other available options.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an .aspx file that outputs an image using the following methods: Server.MapPath(somefile.png)
I need the the .ASPX file to behave differently based on a conditional compilation
I often open .aspx file. I used to do language -> j -> javascript.
I have an updateprogress in my aspx file, which has a label control in
Edit : I've got an aspx file (default.aspx) that loads a flash file (index.swf),
I have a ListView in my aspx file like this: <asp:ListView ID=ListView1 runat=server></asp:ListView> and
Ok so this is a snippet of my aspx file, I am trying to
I'm looking for any resources concerning an ASPX file parser and object model. I'm
How could you do to read a web.config file from inside a aspx file?
I noticed that some aspx controls were not being recognized by intellisense, and when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.