![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
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 />" |
|
|
|
|
|
#2 | ||
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Quote:
Quote:
|
||
|
|
|
|
|
#3 |
|
Hobbyist Programmer
|
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. |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Apr 2005
Posts: 32
Rep Power: 0
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|