Chidi Okeh
Chidi Okeh

Reputation: 1557

Can someone please explain aspx page layout?

I have been reviewing an asp.net application that was written by a former colleague.

There are the following files:

default.aspx and default.aspx.vb
writers.aspx and writers.aspx.vb
forms.aspx and forms.aspx.vb
main.aspx and main.aspx.vb

Here is where confusion creeps in for me.

Default.aspx says:
**CodeBehind="Default.aspx.vb" Inherits="ABA_Reports.Main" %>**

Default.aspx.vb says:
**Partial Public Class Main**

Just to give one more example,

writers.aspx says:
**CodeBehind="Reporter.aspx.vb" Inherits="ABA_Reports._Default" %>**

While writers.aspx.vb has:
**Partial Public Class _Default**

Would someone be kind enough to please explain to me how this works?

Upvotes: 2

Views: 755

Answers (2)

Bert
Bert

Reputation: 82459

Essentially, ASP.NET allows you to split the definition of a web page into two parts. One is a declarative page, where you define the layout of the page using tags (HTML, ASP, or other tags). The declarative part of the page has the ".aspx" extension.

Additionally, there is usually another part of the web page that is defined in a separate file, called the "code behind" file. In your case, with VB, these are the files with the same name as the declarative part of the page, but with the ".aspx.vb" extension.

In the declarative part of the page, the code you mention,

...CodeBehind="Default.aspx.vb" Inherits="ABA_Reports.Main" %>

means that the code behind page for this page is stored in the file Default.aspx.vb. It's also telling you that the declarative part of the page inherits from the Main class in the ABA_Reports namespace defined in code behind file.

The Inherits attribute tells you which class to use in the code behind file. It's probably not immediately clear that you can define multiple classes in the code behind. In many cases (and by default), there is only one, but the Inherits tells you which to use in any case.

Here is a complete explanation of all the attributes that can be included in a @Page declaration, http://msdn.microsoft.com/en-us/library/ydy4x04a.aspx.

In your code behind file you see the line

Partial Public Class Main

Which means that the code behind is defining a "partial" class. All partial really means is that part of the class is defined in the current page, and part of it is defined somewhere else.

The code behind file is there mainly to allow you to separate the code that makes the page run from the HTML and asp and possibly other tags that define how it looks. It also allows the code for the page to be compiled and thereby increase performance.

Upvotes: 1

Hogan
Hogan

Reputation: 70523

Ok, the default namespace is "ABA_Reports".

All classes defined without a namespace listed are going to have that as the start of the name (path).

That is why when the aspx page references the codebehind (the vb class) it uses ABA_Reports.name where name is the class name of the vb file.

Does that make it clear?

Upvotes: 0

Related Questions