473,609 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.c om
http://www.dotnetmonster.com/Uwe/For...p-net/200609/1

Sep 27 '06 #1
5 1513
Hi,

pedestrian via DotNetMonster.c om 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.c om
http://www.dotnetmonster.com/Uwe/For...p-net/200609/1

Sep 27 '06 #3
Hi,

pedestrian via DotNetMonster.c om 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.c om
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
36845
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 code behind. However I am not able to do this at all, I am going about this wrong, I think and need guideance. If this was just straight HTML I would do this: <table> <tr><td>field 1</td><td>value 1 set by code behind</td></tr>
171
7683
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) like it because you can split the code from the design. That is logical. But if you are the only one working on the code, it seem a little overkill. I use Dreamweaver to do my design and find it a bit of a hassle to have multiple files open...
6
5494
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; DataBinder.Eval(Container.DataItem,"StoreEmail") &amp; "&amp;Subject=" &amp; DataBinder.Eval(Container.DataItem,"ProductName") ....
17
2687
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 know nothing about ASP. He can build the design of the pages in HTML with tables, labels, textboxes etc. But then I would need to change them to ASP.net objects and write the code to make the page work (normally I do this as I go - can't do this...
29
3667
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 id="Form1" method="post" runat="server"> <%
1
3635
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 questions that are the same and a few that are different. The problem is that each form contains duplicate UI code and duplicate code in the code behind to handle these duplicate questions... I know, but I inherited the app.
7
2876
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 files to match the .aspx file name so VWD will tie the two together, and I'm now wondering what to do about the location of the code-behind files. Is there any set convention for where the code-behind files live? I have been putting them in the...
7
1744
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. I have a simple page that I made in the beta2 version of VWD. The code behind looks like... using System;
2
3195
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 "not exist in the current context". I thought putting code behind in App_Code folder is the recommendation for asp.net 2. In order to do so, I just simply remove the codefile attribute in @page. Maybe my perception of putting all code in...
2
4812
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 required: <%@ Register TagPrefix="UC" TagName="MyUserCtrl" Src="MyUC.ascx" %> Assuming that the ASPX page doesn't use a code-behind, I can access the properties, events etc. of the user control in the ASPX page in this way (assume that the ASPX page...
0
8130
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8573
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8541
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8222
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4021
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2531
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.