Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 4th, 2006, 7:41 PM   #1
PhilBon
Hobbyist Programmer
 
PhilBon's Avatar
 
Join Date: Nov 2005
Posts: 172
Rep Power: 4 PhilBon is on a distinguished road
Send a message via AIM to PhilBon Send a message via MSN to PhilBon
CodeBehind Vs. No CodeBehind

When is it better to use code behind and to just have code within the aspx page?

say I have
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    hippoasdfkljasdfkljasdfasdf<br />
        <asp:Button ID="Button1" runat="server" Text="Button" /><br />
    asdfasf<br />
    asdfasdfasdf<br/ />
    <br />
    asdfasdfasdfasdf<Br />
    <br />
    this is bob<br />
    bob is round<br />
    bob is fat<br />
    man look at him<br />
    </div>
    </form>
</body>
</html>

and when I hit th botton I want the text to go away and for other text to change to. Plus not stopping there but going from more dynamic ways?
"jack is cool<Br />
jack is 5<br />
he lives in a shoe<br />
he has lots and lots of money<br />"
PhilBon is offline   Reply With Quote
Old Apr 4th, 2006, 8:46 PM   #2
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Quote:
When is it better to use code behind and to just have code within the aspx page?
It depends on the size of the code, if it's a one liner put it inline with the html. Otherwize, i would put it in a seperate file. It is easier to modify if it was in a seperate file.
Quote:
Plus not stopping there but going from more dynamic ways?
there's nothing dynamic about aspx, it's a server side scripting language (although i heard they have some "dynamic" stuff in VS2005). If you want dynamic, you want client-side scripting. Javascript is a good choice.
OpenLoop is offline   Reply With Quote
Old Jun 22nd, 2006, 10:38 AM   #3
hoffmandirt
Hobbyist Programmer
 
hoffmandirt's Avatar
 
Join Date: Jul 2005
Location: PA
Posts: 125
Rep Power: 4 hoffmandirt is on a distinguished road
Send a message via AIM to hoffmandirt
I agree with OpenLoop. Generally if the code is not HTML, I put the code into a separate code file. This makes the code easier to modify, as OpenLoop said, and keeps it modular.

You can get the dynamic text change effect through JavaScript or by handling the click event of the button and setting the innerhtml property. Perhaps you could put the text into a Label control and set the text like that. Either way you can get that dynamic effect. Dynamic only refers to change, it doesn't mean that your only choices are client side languages. You can get change through post backs as well.
hoffmandirt is offline   Reply With Quote
Old Aug 16th, 2006, 1:02 AM   #4
Bharathi
Programmer
 
Join Date: Apr 2005
Posts: 32
Rep Power: 0 Bharathi is on a distinguished road
Hi,

In today's ASP application, we have a mix of HTML and Scripts making the code difficult to read, debug and maintain. ASP.NET relieves us from this problem by promoting the separation of code and content. That is, the user interface and the user interface programming logic need not necessarily be written in a single page. There are two ways in which you can separate the code and content:


1.) By using Code-behind files that are pre-compiled modules written in any of the Microsoft .NET runtime compliant languages.
2.) By developing the frequently used page logic in to separate files called Pagelets (also known as page controls) and by using them several times in your ASP.NET pages.


Regards
bhar
Books for ERP programmers
http://www.vkinfotek.com
Bharathi is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:22 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC