Code behind not in separate file

  • Thread starter Thread starter Terry Olsen
  • Start date Start date
T

Terry Olsen

I didn't choose "code in separate file" when creating a web page. So I have
to use the fully qualified object names because I can't figure out where, or
even if i can, put the Imports statement. Can anyone shed some light on
this? What are the limitations when you have the server-side code in the
aspx file?
 
Terry said:
I didn't choose "code in separate file" when creating a web page. So I have
to use the fully qualified object names because I can't figure out where, or
even if i can, put the Imports statement. Can anyone shed some light on
this? What are the limitations when you have the server-side code in the
aspx file?

Hi,

When you are using server side codes in aspx page , you can still use
the import statement but in a different way.

just put the import statement below you page declaration

<%@ Page Language="C#" %>
<%@ Import Namespace="MyPackage.MyNameSpace" %>

thats it...

But its better to use code behind file.

Code behind file is introduced to make your code more maintainable
and separating the code logic from the page helps enforce the MVC
pattern.

Thanks
Masudur
kaz Software Ltd.
www.kaz.com.bd
 
Hi,

Terry said:
I didn't choose "code in separate file" when creating a web page. So I have
to use the fully qualified object names because I can't figure out where, or
even if i can, put the Imports statement. Can anyone shed some light on
this? What are the limitations when you have the server-side code in the
aspx file?

There are many disadvantages to having the code in the ASPX file. First,
you don't have the clean separation between UI and code, then you must
publish the uncompiled code to the server, and finally as you found out,
linking to other libraries is more difficult.

I strongly recommend you to use code-behind files.

HTH,
Laurent
 
Back
Top