473,666 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1840
"Mitch A" <ex****@exc.dom > wrote in
news:3f******** **@newspeer2.td s.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.Instanc e.GetCompanyNam e() %>
</TITLE>
<SCRIPT type="text/javascript"
src="../../scripts/clipboard.js">
</SCRIPT>
<%= Globals.Instanc e.GetCommentHea der() %>
<META name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
<%= Globals.Instanc e.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="parentRepea ter" runat="server">
<itemtemplate >
<table cellpadding=0 cellspacing=0 border=0 width=80% >
<td class="CandInfo "width="100 %">
<%# DataBinder.Eval (Container.Data Item, "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.td s.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:Repeate r id="parentRepea ter" runat="server">
<itemtemplate >
<table cellpadding=0 cellspacing=0 border=0 width=80% >
<td class="CandInfo "width="100 %">
<%# DataBinder.Eval (Container.Data Item, "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.W ebControls.Repe ater 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
2752
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 properties in code? I am using Visual Studio 2003, building an ASP.NET web application using VB.NET.
1
1003
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 variable? VBScript please.
4
5534
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 runs. I tried to define another Button with an EventHandler associated, and from this (after doing my code) fire 'btnSearch.click()'. But I can't make it work. I tried private void Button1_Click(object sender, System.EventArgs e RestartAll()...
1
2420
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. e.g. following code is written in File Name: Test.aspx.vb Imports System.Data Dim cCode as String cCode = "ABC"
4
1462
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 did this was: Response.ContentType = contentType; Response.BinaryWrite(((MemoryStream)proc.GetReport()).ToArray()); Response.End();
2
5184
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 = document.getElementById(divID) x.style.display == 'block'? x.style.display='none' : x.style.display='block'; } In the code behind page, I want to use the value of the display property to
5
1988
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 wrong with the code below? I have put a hyperlink on the aspx page. And I add the attributes of the hyperlink in my code-behind. I set the attributes in code behind because I need the AddressGuid ID value. I concattenate the value and make an URL...
2
2130
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 behind(C#). I tried like this... public string SSN { get { return request.querystring;
4
3097
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 ID="lblCustomer">Customer Name: </asp:Label> <asp:TextBox Style="color:Red" runat=server ID="txtCustomer" OnFocus="clearDefault(this)">Enter Customer Name</asp:TextBox>&nbsp&nbsp&nbsp <asp:Button runat=server ID=cmdSubmit...
0
8445
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
8871
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
8781
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
8551
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
7386
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
6198
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
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
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...
1
2771
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

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.