473,386 Members | 1,758 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,386 software developers and data experts.

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="<%=myImageString%>" />

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 1106
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@localhost> wrote in message
news:OH**************@tk2msftngp13.phx.gbl...
What is the general opinion of having code in the html section of an asp.net page. For example..

<img src="<%=myImageString%>" />

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@localhost> wrote in message
news:OH**************@tk2msftngp13.phx.gbl...
What is the general opinion of having code in the html section of an asp.net page. For example..

<img src="<%=myImageString%>" />

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@localhost> a écrit dans le message de
news:OH**************@tk2msftngp13.phx.gbl...
What is the general opinion of having code in the html section of an asp.net page. For example..

<img src="<%=myImageString%>" />

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**************@TK2MSFTNGP12.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@localhost> a écrit dans le message de
news:OH**************@tk2msftngp13.phx.gbl...
What is the general opinion of having code in the html section of an asp.net
page. For example..

<img src="<%=myImageString%>" />

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@localhost> wrote in message
news:OH**************@tk2msftngp13.phx.gbl...
What is the general opinion of having code in the html section of an asp.net page. For example..

<img src="<%=myImageString%>" />

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
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...
13
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...
40
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...
15
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...
7
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...
11
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...
232
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...
13
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...
12
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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...

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.