473,796 Members | 2,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code Behind Question

Hi I am designing an ASP.net app. Just wanted some opinions on code behind
options. My idea is to have a code behind file that the controls will
reference and have ascx files for the controls. Then have the aspx pages
call the controls. Is this a good approach? I wanted to throw all my
business logic in to the code behind file and then on the aspx pages that
use the controls just refernce the ascx files. Is this the correct
approach? Should I bypass the ascx controls if they are not fancy customer
controls just like a datagrid? Also I connect to SQL back end in the app
and get different data for some of the datagrids that will be on the main
page? Is it better to put the ADO.net connection logic in to the ascx
files? or better to use the Code Behind? Thanks for any opinions.

Regards,
Chris
Nov 18 '05 #1
1 1269
Do not think of CodeBehind as a file, or you're already in trouble. It isn't
a "file" to your application. It is a class definition. It is the class
definition for a given Page. The class definition is simply split into a
Template (.aspx) and a class definition.

A Page is a System.Web.UI class, which means that it is a User Interface. As
such, it isn't a good idea to put much (if any) business logic into it. Your
business logic should reside in Business classes, classes that work with
data and have no User Interface. The Page is then the User Interface, with
all the User Interface elements in it, and the only logic in the Page should
deal with presenting the data from the data classes in the page, and
allowing the User to interact with it. The Page should interact with the
business objects via the business class programming interface.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Chris Kettenbach" <ch***@piasd.or g> wrote in message
news:qh******** ***********@new ssvr13.news.pro digy.com...
Hi I am designing an ASP.net app. Just wanted some opinions on code behind options. My idea is to have a code behind file that the controls will
reference and have ascx files for the controls. Then have the aspx pages
call the controls. Is this a good approach? I wanted to throw all my
business logic in to the code behind file and then on the aspx pages that
use the controls just refernce the ascx files. Is this the correct
approach? Should I bypass the ascx controls if they are not fancy customer controls just like a datagrid? Also I connect to SQL back end in the app
and get different data for some of the datagrids that will be on the main
page? Is it better to put the ADO.net connection logic in to the ascx
files? or better to use the Code Behind? Thanks for any opinions.

Regards,
Chris

Nov 18 '05 #2

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

Similar topics

242
13464
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any comments on past experience, research articles, comments on the matter would be much appreciated. I suspect something like C would be the best based on comments I received from the VB news group. Thanks for the help in advance James Cameron
171
7800
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
5517
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
2721
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...
7
2886
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
1753
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
3204
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...
1
1244
by: archana | last post by:
Hi all, I am new to asp.net. I have one question regarding code- behind model. I have written page_load event in code behind as well as in aspx page. Means i am doing mixing of code-behind as well as single file model. Is it possible to write some code in code behind and some in aspx page itself.
0
9685
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
9533
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
10239
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...
0
9057
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7555
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
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
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
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.