understanding ASP.NET web page coding model

understanding ASP.NET web page coding model

ASP.NET web page coding model:-

  • ASP.net provides two models for managing the visual elements and code.
  1. inline code
  2. code-behind file
  • these two code model’s functionality is the same.
  • we can use the same controls and code for both models.
  • at runtime model execute the same way.
  • there is no performance difference between them.

let’s talk about these two models.

inline code model:-

  • it is a single-file.
  • HTML code+programming code in the same .aspx file.
  • the programming code is contained in a<script> block that specifies the attribute runat=”server” to mark it as code that ASP.NET should run.
inline code model

inline code model

  • in an above example unchecks the checkbox.
  • we can see that there are only three views like design view, split view, source view.
  •  there is no separate coding view.
inline code model

inline code model

  • we can see that HTML code and programming code are on a single page. the result code is written in Default.aspx

advantages of inline code model(single-file):-

  • there is not very much code, the convenience of keeping the code and markup in the same file.
  • pages written using the single-file model are easier to deploy or to send to another programmer because there is only one file.
  • easier to rename.
  • the number of the file in the project is less.

code-behind model:-

  • the code behind model allows you to keep the HTML code in one file and programming code in another file.
  • the extension of code-behind file depends on the programming language you select.
  • for example, if you are working with a page named product, the HTML coding is placed in the file product.aspx and code are created in the file named product.aspz.vb(for vb) or product.aspx.cs(for C#)
  • code-behind model

    code-behind model


  • two separate files are: the first file is designing in HTML(.aspx), the second file is for coding in VB.NET(.aspx.vb)


advantages of code-behind model:-

  • it offers clean separation of markup and code.
  • it is practical to have a designer working on the markup while a programmer writes code.
  • the code can be reused for multiple languages.