473,406 Members | 2,336 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,406 software developers and data experts.

inline code VS page behind code

What are the advantages of using inline C# code in my aspx pages (with
inline I mean directly in the html between <% %>) versus code behind. It
seems messy and inelegant to have code in both places (IMHO, using inline
*and* code-behind is not object oriented and it generates less readable
code). Since code behind offers syntax highlighting, autocompletion, member
info, parameterinfo etc, is there any reason (design or other) I
couldn't/shouldn't write all code strictly using code-behind.
Nov 17 '05 #1
3 1821
"Mitch A" <ex****@exc.dom> wrote in
news:3f**********@newspeer2.tds.net:
What are the advantages of using inline C# code in my aspx pages
(with inline I mean directly in the html between <% %>) versus
code behind. It seems messy and inelegant to have code in both
places (IMHO, using inline *and* code-behind is not object
oriented and it generates less readable code). Since code
behind offers syntax highlighting, autocompletion, member info,
parameterinfo etc, is there any reason (design or other) I
couldn't/shouldn't write all code strictly using code-behind.


Mitch,

I can't think of any. I use code-behind as much as possible. I only
use inline <%= %> tags if I need to insert some text at runtime in a
place where ASP.Net tags can't be used (or at least not easily used).

The <HEAD> section of an HTML page is a good example. What few
inline tags I do use I keep very short, and any actual calculations
are done in code-behind:

<HEAD>
<TITLE>
<%= Globals.Instance.GetCompanyName() %>
</TITLE>
<SCRIPT type="text/javascript"
src="../../scripts/clipboard.js">
</SCRIPT>
<%= Globals.Instance.GetCommentHeader() %>
<META name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<%= Globals.Instance.GetMetaTags() %>
<LINK rel="stylesheet" type="text/css" href="../../portal.css">
</HEAD>

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 17 '05 #2
Thanks for responding Chris. Is it possible to manipulate ASPNET server
controls using only codebehind? For example, I have the following bit of
code currently embdedded in the HTML:

<asp:Repeater id="parentRepeater" runat="server">
<itemtemplate>
<table cellpadding=0 cellspacing=0 border=0 width=80% >
<td class="CandInfo"width="100%">
<%# DataBinder.Eval(Container.DataItem, "NM_FRST") %>
<td> </table>
</itemtemplate>
</asp:Repeater>
Other than the HTML tags identifying the control (<asp:Repeater>), can any
of this code be moved to the webform Page_Load event?




Nov 17 '05 #3
"Mitch A" <ex****@exc.dom> wrote in
news:3f**********@newspeer2.tds.net:
Thanks for responding Chris. Is it possible to manipulate
ASPNET server controls using only codebehind? For example, I
have the following bit of code currently embdedded in the HTML:

<asp:Repeater id="parentRepeater" runat="server">
<itemtemplate>
<table cellpadding=0 cellspacing=0 border=0 width=80% >
<td class="CandInfo"width="100%">
<%# DataBinder.Eval(Container.DataItem, "NM_FRST") %>
<td> </table>
</itemtemplate>
</asp:Repeater>
Other than the HTML tags identifying the control
(<asp:Repeater>), can any of this code be moved to the webform
Page_Load event?


Mitch,

I suppose it's technically possible to do so (see the help entry for
the System.Web.UI.WebControls.Repeater class). Personally, I don't
create controls in code unless I absolutely have to. I find it
easier to use the property editor to manipulate the control, and use
code-behind for everything else. The less code I have to actually
write, debug and maintain, the happier I am :-).

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 17 '05 #4

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

Similar topics

7
by: Cliff Cavin | last post by:
How do I programatically change the background color of an aspx page in code? Is there something like Page.BgColor = "#FFFFFF" ? For that matter, how do I access any of the DOCUMENT...
1
by: Robert | last post by:
I have a User Control. Is it possible to define a variable in the User Control HTML like this < Dim strTem % and then use the page behind code in the Page_Load event to update this strTemp...
4
by: Carlo Marchesoni | last post by:
I have a button that opens a new Window (some kind of search-window), which is fired using JavaScript (btnSearch.Attributes=".....";) Now I need to run some code behind code BEFORE this JavaScript...
1
by: Kamal Ahmed | last post by:
Hi All, I have an aspx file written using vb.net that contains code both in code behind and inline. I want to access variable, object/classes declared in code behind into inline .aspx file....
4
by: David Thielen | last post by:
Hi; I have a page where the file.aspx.cs Page_Load() method writes the entire contents out directly. I use this to write a pdf or rtf file as the web page to display. In .net 1.1 the way I...
2
by: Italian Pete | last post by:
Hi, I have a div control on an aspx page. I toggle the display property between 'block' and 'none' client side using the following javascript: function toggleDivOnOff(divID) { var x =...
5
by: mesut | last post by:
Hi there, how are you colleagues? I try to set a linkaddress in code behind for a <asp:hyperlinkserver control. but I think I have some syntax problem. I don't know how to fix it. What's...
2
by: 111111222222 | last post by:
I have a grid view with a SSN column as a hyperlink. Whenever I click SSN I want to populate grid view in same page for that particular SSN. For this I need to pass SSN from aspx page to code...
4
by: Kratos2005 | last post by:
I have a ASP.Net Page with code behined in C#. as below <body> <form id="form1" runat="server"> <table align=center > <tr> <td> <asp:Label runat=server...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
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...

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.