473,406 Members | 2,312 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.

Seperating code from HTML markup

Joe
Hello All:

I am writing to ask for your opinions. I have a colleague who combines his
code with the markup used to display the code (reckoning back to classic
ASP). Here's an example of a datagrid column:

<asp:TemplateColumn>
<ItemStyle CssClass="TableData" Width="15%"></ItemStyle>
<ItemTemplate>
<a href="<%# ShowURL(DataBinder.Eval(Container.DataItem,
"FORM_ID"))%>" target="_blank">
<%# DataBinder.Eval(Container.DataItem, "FORM_NUMBER")%></a>
</ItemTemplate>
</asp:TemplateColumn>

or another column

<asp:TemplateColumn>
<ItemStyle CssClass="TableData" Width="20%"></ItemStyle>
<ItemTemplate>
<%# DisplayState(DataBinder.EvalContainer.DataItem,
"FORM_STATE_CD"))%>
</ItemTemplate>
</asp:TemplateColumn>

Where ShowURL and DisplayState are defined in the code-behind. We have the
restriction that we can not use ViewState when creating our webforms
(security breach due to how they have architected their web app). I wonder
if there is a bettre way to do this.

In my opinion, this is sloppy programming. I, however, could be wrong.
Maybe this is the best way to do this. So I am asking:

What is your opinion regarding mixiing content and functionality.

If you think that this could have been done differnetly, What would you have
done? Is there a better way to do this?

Finally, the IDE will not display the Design View of the page that contains
this markup. The message says "Could not open in Design View. Quote values
differently inside of a '<% ...value... %>' block."

Thank you for your input.
--
Joe
Feb 15 '06 #1
2 1734
As for the designer error, simply switching:
a href="<%# ShowURL(DataBinder.Eval(Container.DataItem, "FORM_ID"))%>"
target="_blank">

to:

a href='<%# ShowURL(DataBinder.Eval(Container.DataItem, "FORM_ID"))%>'
target="_blank">

should solve that (replace the " around the <%# ... %> with ' )

As far as I'm concerned, the question is pretty trivial. The separation of
code and HTML is almost complete in your examples below. ShowURL and
DisplayState both represent functionality that resides outside the HTML, and
if it needs to be reused, it could easily be extracted to a seperate code
file. The only way to achieve even greater separation is to hook into the
OnItemDataBound event and write a considerable chunk of code. For any
complex binding, this will result in a lot of code generating HTML. I've
seen code that took this approach, and it's an absolute nightmare. You end
with huge amounts of html created in code (new Table(), new TableRow(),
table.Rows.Add(tr), new TableCell(), new Label(), label.Text = SomeDBValue;
cell.Controls.Add(label), row.Cells.Add(cell)....), which is far harder to
maintain and change than the examples below.

The code has pretty good abstraction

1 - it uses methods located in codebehind for any actual processing
2 - It uses DataBinder.Eval which abstracts away the business layer
implementation (is Container.DataItem a datarowview ora custom class? who
knows, and why should the presentation layer care?)

I think you'll find that the benefits of further separation aren't worth
the high price you'll end up paying

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Joe" <Jo*@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
Hello All:

I am writing to ask for your opinions. I have a colleague who combines
his
code with the markup used to display the code (reckoning back to classic
ASP). Here's an example of a datagrid column:

<asp:TemplateColumn>
<ItemStyle CssClass="TableData" Width="15%"></ItemStyle>
<ItemTemplate>
<a href="<%# ShowURL(DataBinder.Eval(Container.DataItem,
"FORM_ID"))%>" target="_blank">
<%# DataBinder.Eval(Container.DataItem, "FORM_NUMBER")%></a>
</ItemTemplate>
</asp:TemplateColumn>

or another column

<asp:TemplateColumn>
<ItemStyle CssClass="TableData" Width="20%"></ItemStyle>
<ItemTemplate>
<%# DisplayState(DataBinder.EvalContainer.DataItem,
"FORM_STATE_CD"))%>
</ItemTemplate>
</asp:TemplateColumn>

Where ShowURL and DisplayState are defined in the code-behind. We have
the
restriction that we can not use ViewState when creating our webforms
(security breach due to how they have architected their web app). I
wonder
if there is a bettre way to do this.

In my opinion, this is sloppy programming. I, however, could be wrong.
Maybe this is the best way to do this. So I am asking:

What is your opinion regarding mixiing content and functionality.

If you think that this could have been done differnetly, What would you
have
done? Is there a better way to do this?

Finally, the IDE will not display the Design View of the page that
contains
this markup. The message says "Could not open in Design View. Quote
values
differently inside of a '<% ...value... %>' block."

Thank you for your input.
--
Joe

Feb 15 '06 #2
Joe
Thank you Karl. This helped. As always, I appreciate your input.
--
Joe
"Karl Seguin [MVP]" wrote:
As for the designer error, simply switching:
a href="<%# ShowURL(DataBinder.Eval(Container.DataItem, "FORM_ID"))%>"
target="_blank">

to:

a href='<%# ShowURL(DataBinder.Eval(Container.DataItem, "FORM_ID"))%>'
target="_blank">

should solve that (replace the " around the <%# ... %> with ' )

As far as I'm concerned, the question is pretty trivial. The separation of
code and HTML is almost complete in your examples below. ShowURL and
DisplayState both represent functionality that resides outside the HTML, and
if it needs to be reused, it could easily be extracted to a seperate code
file. The only way to achieve even greater separation is to hook into the
OnItemDataBound event and write a considerable chunk of code. For any
complex binding, this will result in a lot of code generating HTML. I've
seen code that took this approach, and it's an absolute nightmare. You end
with huge amounts of html created in code (new Table(), new TableRow(),
table.Rows.Add(tr), new TableCell(), new Label(), label.Text = SomeDBValue;
cell.Controls.Add(label), row.Cells.Add(cell)....), which is far harder to
maintain and change than the examples below.

The code has pretty good abstraction

1 - it uses methods located in codebehind for any actual processing
2 - It uses DataBinder.Eval which abstracts away the business layer
implementation (is Container.DataItem a datarowview ora custom class? who
knows, and why should the presentation layer care?)

I think you'll find that the benefits of further separation aren't worth
the high price you'll end up paying

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Joe" <Jo*@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
Hello All:

I am writing to ask for your opinions. I have a colleague who combines
his
code with the markup used to display the code (reckoning back to classic
ASP). Here's an example of a datagrid column:

<asp:TemplateColumn>
<ItemStyle CssClass="TableData" Width="15%"></ItemStyle>
<ItemTemplate>
<a href="<%# ShowURL(DataBinder.Eval(Container.DataItem,
"FORM_ID"))%>" target="_blank">
<%# DataBinder.Eval(Container.DataItem, "FORM_NUMBER")%></a>
</ItemTemplate>
</asp:TemplateColumn>

or another column

<asp:TemplateColumn>
<ItemStyle CssClass="TableData" Width="20%"></ItemStyle>
<ItemTemplate>
<%# DisplayState(DataBinder.EvalContainer.DataItem,
"FORM_STATE_CD"))%>
</ItemTemplate>
</asp:TemplateColumn>

Where ShowURL and DisplayState are defined in the code-behind. We have
the
restriction that we can not use ViewState when creating our webforms
(security breach due to how they have architected their web app). I
wonder
if there is a bettre way to do this.

In my opinion, this is sloppy programming. I, however, could be wrong.
Maybe this is the best way to do this. So I am asking:

What is your opinion regarding mixiing content and functionality.

If you think that this could have been done differnetly, What would you
have
done? Is there a better way to do this?

Finally, the IDE will not display the Design View of the page that
contains
this markup. The message says "Could not open in Design View. Quote
values
differently inside of a '<% ...value... %>' block."

Thank you for your input.
--
Joe


Feb 15 '06 #3

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

Similar topics

19
by: R. Rajesh Jeba Anbiah | last post by:
I would like to know what HTML standard will be better for PHP webapplications? Right now, I use HTML 4.01 Transitional. And like to know what *you* PHP programmers prefer? and which is good? TIA....
4
by: Sergio del Amo | last post by:
i, I have the next html page <html> <head> <script> <!-- function insertcode() { var code ="<p> blablabal babala babababab</p><h1>here comes header</h1><span>fadfafa<a...
1
by: Wladimir Borsov | last post by:
I want to mark certain text on a web page in InternetExplorer and then copy and paste it into a normal text editor. With the copied text not only the pure text should be transferred but also the...
21
by: BT | last post by:
I inherited a simple page that needs to be Strict HTML and I'm not very familiar with this standard. What I'm trying to do _should be_ pretty simple so I hope someone can point me in the right...
25
by: Delta | last post by:
Drop Down Menu Mozilla : work well widowed elements such as drop downs, except for flash movies IE : work well so far http://pwp.netcabo.pt/falmartins/index.htm
52
by: Andy Dingley | last post by:
I'm using this at present: <p title="Publication date" ></p> Works fine on screen, but Fangs/Jaws just reads it as "left bracket twenty-eight slash zero slash two thousand five fifteen colon...
16
by: graham.reeds | last post by:
I am updating a website that uses a countdown script embedded on the page. When the page is served the var's are set to how long the countdown has left in minutes and seconds, but the rest of the...
25
by: Jon Slaughter | last post by:
I have some code that loads up some php/html files and does a few things to them and ultimately returns an html file with some php code in it. I then pass that file onto the user by using echo. Of...
13
Death Slaught
by: Death Slaught | last post by:
I have my entire page in my "main" div. div.main { width: 100%; height: 100%; border: 1px solid gray; } on the left of the page I have a banner.
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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...
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
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.