473,666 Members | 2,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code in the HTML, bad idea?

What is the general opinion of having code in the html section of an asp.net
page. For example..

<img src="<%=myImage String%>" />

I see something like that done many times in examples, but I'm wondering if
this is a good practice, or something to be avoided. If one of the goals of
asp.net was to separate html from code, this just seems to be going back to
the old "asp" ways.

Nov 18 '05 #1
5 1117
Michael,

There are times when its easier just to use embedding !!! specially when you
are dealing with html controls.
Then there are times when you could like to see how its going to be instead
of manipulating one param
Take the example of a data grid... you can customise what columns get shown
and whether they are directly bound to the datasource or whether they are
template based.
yes you can do most of the things from code behind but code behind doesnt
emit things at design time.... unless of course you start writing custom
controls for just about everything.

So i guess its a personal choice really... depends on whether you like to
keep it uniform... or you could like to take extra effort in order to keep
it extra clean,

Regards,

HD

"Michael" <raterus@localh ost> wrote in message
news:OH******** ******@tk2msftn gp13.phx.gbl...
What is the general opinion of having code in the html section of an asp.net page. For example..

<img src="<%=myImage String%>" />

I see something like that done many times in examples, but I'm wondering if this is a good practice, or something to be avoided. If one of the goals of asp.net was to separate html from code, this just seems to be going back to the old "asp" ways.

Nov 18 '05 #2
I wouldn't use what you are showing at all, ever. That's the "classic asp"
way to do it and it is not as efficient as .NET techniques.

With
"Michael" <raterus@localh ost> wrote in message
news:OH******** ******@tk2msftn gp13.phx.gbl...
What is the general opinion of having code in the html section of an asp.net page. For example..

<img src="<%=myImage String%>" />

I see something like that done many times in examples, but I'm wondering if this is a good practice, or something to be avoided. If one of the goals of asp.net was to separate html from code, this just seems to be going back to the old "asp" ways.

Nov 18 '05 #3
Something that could be perhaps acceptable is :
- if no programmatic id, you can't access it from your code behind. Inline
code is allowed.
- if a value is set once but never changed (such as a common function that
would retrieve localized strings from a database), inline code allowed.

If the value can change depending on the events (for example you change the
image if you meet some other condition at load time or after a postback or
whatever else) keep it in code, inline code to be avoided.

Basically the idea would be to allow inline code for one time initialization
expressions and to avoid inline code when you have some further processing
for this property... Of course always a matter of personal taste...

Patrice

--

"Michael" <raterus@localh ost> a écrit dans le message de
news:OH******** ******@tk2msftn gp13.phx.gbl...
What is the general opinion of having code in the html section of an asp.net page. For example..

<img src="<%=myImage String%>" />

I see something like that done many times in examples, but I'm wondering if this is a good practice, or something to be avoided. If one of the goals of asp.net was to separate html from code, this just seems to be going back to the old "asp" ways.


Nov 18 '05 #4
The basic idea behind the ASP.Net CodeBehind model is that it is difficult
to both develop and especially maintain the software when interface HTML and
executable server-side code are mixed up together. I agree wholeheartedly
with this philosophy, as I have had to work on far more than my share of
poorly-organized ASP code. Good coding practice dictates that code should be
well-optimized, well-organized, and well-conceived. The placement of the
code in the HTML would have very little effect on the actual execution of
the Page. However, it might have a great effect on how long it would take
another developer to make any changes in the Page in the future.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Patrice Scribe" <no****@nowhere .com> wrote in message
news:Or******** ******@TK2MSFTN GP12.phx.gbl...
Something that could be perhaps acceptable is :
- if no programmatic id, you can't access it from your code behind. Inline
code is allowed.
- if a value is set once but never changed (such as a common function that
would retrieve localized strings from a database), inline code allowed.

If the value can change depending on the events (for example you change the image if you meet some other condition at load time or after a postback or
whatever else) keep it in code, inline code to be avoided.

Basically the idea would be to allow inline code for one time initialization expressions and to avoid inline code when you have some further processing
for this property... Of course always a matter of personal taste...

Patrice

--

"Michael" <raterus@localh ost> a écrit dans le message de
news:OH******** ******@tk2msftn gp13.phx.gbl...
What is the general opinion of having code in the html section of an asp.net
page. For example..

<img src="<%=myImage String%>" />

I see something like that done many times in examples, but I'm wondering

if
this is a good practice, or something to be avoided. If one of the

goals of
asp.net was to separate html from code, this just seems to be going back

to
the old "asp" ways.

Nov 18 '05 #5
I dont think its considered good practice and i think anyone would tell you
that its preferable to put as much code in code-behind as possible, but
realistically speaking sometimes its just easier/faster (in the short term)
to put stuff like this directly in html.
i believe one of the benefits of this quickie approach is that it doesnt
require you to recompile from VS.NET. you can just edit this file in
Notepad or something and copy the new file onto the server.

"Michael" <raterus@localh ost> wrote in message
news:OH******** ******@tk2msftn gp13.phx.gbl...
What is the general opinion of having code in the html section of an asp.net page. For example..

<img src="<%=myImage String%>" />

I see something like that done many times in examples, but I'm wondering if this is a good practice, or something to be avoided. If one of the goals of asp.net was to separate html from code, this just seems to be going back to the old "asp" ways.

Nov 18 '05 #6

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

Similar topics

0
2410
by: Chris McKeever | last post by:
I am trying to modify the Mailman Python code to stop mapping MIME-types and use the extension of the attachment instead. I am pretty much clueless as to what I need to do here, but I think I have narrowed it down to the Scrubber.py file.. If this seems like a quick step me through, I would be very appreciative, could get you something on your Amazon wish-list (that is me on my knees begging).. From just my basic understanding, it...
13
2400
by: Fernando Fernández | last post by:
Hi people :)) I am Fernando and I have made a web application with HTML and JavaScript. Now I would like to hide the source code, or at least my JavaScript source code. Is it possible? is there a method for doing it? Thanks you from Palma de Mallorca, Spain Fernando
40
2784
by: GTi | last post by:
Is there any source code documentation tools available for Visual Studio 2005 ? I have created a LIB that must be documented. Must I do it by hand or is it some kind of tools to pre document my source code?
15
4597
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to communicate with a MySQL database table on a web server, from inside of my company's Access-VBA application. I know VBA pretty well but have never before needed to do this HTTP/XML/MySQL type functions.
7
1770
by: Trickynick1001 | last post by:
Hi, a newbie here. I don't have a real firm grasp on the idea of Javascript, as I'm used to programming in Qbasic and C. I'm not used to OOP. Anyway, I really don't have any idea what the problem is with this code, it just simply won't work properly. Some of the functions aren't done, but the main one gives me a Not a Number message in the text box where the calculations are supposed to come up. I tried to use a parseInt on my stuff,...
11
3141
by: saurabh | last post by:
Can anybody tell me how to change the value of an html control from the c#.... eg i hv one asp.net radio button control and one html hidden variable... so on page load in case the radio button is checked i want to set this hidden variable to 1 else 0... I am not getting what to write in Page_Load(object sender, System.EventArgs e) function to change the value of this html variable...
232
13242
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
13
3543
by: Bob Jones | last post by:
Here is my situation: I have an aspx file stored in a resource file. All of the C# code is written inline via <script runat="server"tags. Let's call this page B. I also have page A that contains some javascript code that calls window.open. I pass the resource url of page B to Page A's window.open call. Page B is then loaded and executed but none of the server-side code is rendered. If I view the source of the page, the code (and page...
12
13332
by: backups2007 | last post by:
How do I submit form entries to the database and redirect to the same page, with the entries still display on the fields of the form? I really need help on this. Thanks.
0
8448
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
8356
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
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...
1
8552
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
8640
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5666
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...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.