473,395 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ASP.NET 2.0: To use or not to use code behind?

I'm just beginning to learn ASP.NET 2.0. I wonder what's the reason for
using or not using the code behind file?

Thanks for replying...

--
Regards,
Pedestrian, Penang.

Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200609/1

Sep 27 '06 #1
5 1506
Hi,

pedestrian via DotNetMonster.com wrote:
I'm just beginning to learn ASP.NET 2.0. I wonder what's the reason for
using or not using the code behind file?

Thanks for replying...
Do you mean using code behind as opposed to writing the code inline in
the ASPX page?

Though this last possibility exists, it should not be used except in
very specific cases (of which I cannot even imagine one).

An ASPX without any code behind is also possible. For example, yu might
want to use an ASPX page to display HTML code and custom (or user)
controls only, in which case the ASPX page's code behind file may be
deleted.

In all other cases, it is recommended to use code-behind files to
implement your server-side logic, and not inline. There are many
advantages to that:

- Your CS code will be compiled in DLLs, instead of being placed in
clear text on the server. The DLLs may even be encrypted if your firm
wishes to protect the code.

- It allows a much better encapsulation of the code, and allows a better
OO design.

- Maintainability is better when the C# code, CSS code, JavaScript code
and ASPX code are in different files. It's easier to identify and modify
files this way, instead of having everything in the same file.

- I am sure there are more.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Sep 27 '06 #2
Thanks for your reply, Laurent. I haven't told that I'm using VB2005 for
ASP.NET 2.0... Thanks.

--
Regards,
Pedestrian, Penang.

Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200609/1

Sep 27 '06 #3
Hi,

pedestrian via DotNetMonster.com wrote:
Thanks for your reply, Laurent. I haven't told that I'm using VB2005 for
ASP.NET 2.0... Thanks.
You mean VB.NET, I suppose. Anyway, it doesn't matter, everything I said
applies to VB.NET as well as C#.

Greetings,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Sep 27 '06 #4
That's right, I'm using VB.NET. Thanks.

--
Regards,
Pedestrian, Penang.

Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200609/1

Sep 28 '06 #5
(of which I cannot even imagine one).

Repeaters and ItemTemplates.

I personally would never rule out using inline code, along with any
other language feature. Your point about clear text code in your ASPX
is taken, but I can't say it should be a negative for just one side of
the argument. DLL's are decompilable, and if the bad people are
wandering around inside your server then inline code is not your
biggest concern. Lets assume a hacker compromises your server and has
access to your aspx files, as well as DLLs. They're most likely to copy
the entire site regardless and decompile your DLL. Inline code is no
more of a threat than code behind.

Maintainability is still highly relevant though...

Sep 28 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Richard Dixson | last post by:
I created a new C# web application. Basically all I am trying to do is create a table that consists of a few rows with two columns in each. And then to set those columns to text values from my...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
6
by: Paolo Pignatelli | last post by:
I have an aspx code behind page that goes something like this in the HTML view: <asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<%#"mailto:" &amp;...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
29
by: John Rivers | last post by:
Hello, What good reason there is for not allowing methods in ASPX pages I can't imagine, but here is how to get around that limitation: (START) <body MS_POSITIONING="FlowLayout"> <form...
1
by: Me | last post by:
Hi, I inherited a web application that has several very similar forms for gathering user data. User's must choose the form that best fits their needs and fill it out. Each form has about 15...
7
by: Alan Silver | last post by:
Hello, I am just looking at VWD and seeing what needs doing to take an existing site I've written by hand and importing it into VWD. I've already discovered that I need to rename my code-behind...
7
by: Alan Silver | last post by:
Hello, I have installed the 2.0 framework, and am looking at converting some of my 1.1 pages to use partial classes. I don't (yet) have VS2005, so I'm doing this by hand, but am having problems....
2
by: walter | last post by:
Hi, when I add a new page in my asp.net 2 project and put some controls there, everything works fine until I move the code behind into App_Code folder.--When I compile , it tells me that control...
2
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.