dtakis
dtakis

Reputation: 581

Why should i include the namespace in each aspx page?

I usually include my namespaces e.g.

using myProject.Model; 

to my .cs files but when i want to iterate an object derived from myProject.Model in my .aspx file i must always include the directive

<%@ Import Namespace="myProject.Model" %>

Why is that? I mean if it is declared in code behind file (in default.aspx.cs) of default.aspx Why should i add it again? Why it is not available?

Just wondering but i would like to know why is that.

Thank you in advance!

Upvotes: 2

Views: 3835

Answers (3)

to StackOverflow
to StackOverflow

Reputation: 124726

You can add a namespaces element to your web.config to specify namespaces that you'd like to be imported automatically.

Upvotes: 4

Alessandro
Alessandro

Reputation: 3760

Because the @Import directive allows you to specify the namespaces to be imported for the Asp.Net pages or user controls, while import keyword is used to specify the namespaces to be imported for the codebehind.

Upvotes: 1

Freeman
Freeman

Reputation: 5801

Because the ASPX pages are compiled using a different "WebPage" compiler, you must specify the namespaces for each page on wich you requrire certain features form that namespace.

Upvotes: 2

Related Questions