Re: Seperating code from HTML markup

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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" <Joe@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:65EF2A6E-0440-4DFC-B8B5-AE49C4C8BBA1@xxxxxxxxxxxxxxxx
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



.



Relevant Pages

  • Re: Application logic and Business logic
    ... HTML and HTTP put *restraints* on UI flow that client/server systems ... business layer to have hardwired itself to a specific table layout is ... Separation creats a mini-buerocracy. ... (* Better to treat the database as a huge object... ...
    (comp.object)
  • Re: Perl DBI Module: SQL query where there is space in field name
    ... there is no reason to open let alone save the garbage part this way at ... simply ignore than huge pile of utterly useless HTML crap. ... huge amount of total crap and thus causes negativity - as I can see ... that is indeed my opinion on this case of the meaning for "my way". ...
    (comp.lang.perl.misc)
  • Re: Event Handling via CSS
    ... Ask your fellow jQuery mavens. ... html, that responds for the vast majority of living websites. ... XHTML served as HTML is not "current web technology", ... About not being "too hot" with HTML, that's a personal opinion. ...
    (comp.lang.javascript)
  • Re: Which spec to use?
    ... am venturing out into the design area and need an opinion please. ... HTML 4.01 or XHTML 1.0 both being strict. ... Is that still true with IE8? ... I asked because I have read some things that indicate that IE8 is so W3C compliant that sites built to use IE6-type proprietary technology probably won't work with IE8. ...
    (alt.html)
  • Re: CSS software tools sought
    ... I don't see that as horrible but of course you're entitled to your opinion. ... What four lines of Perl can do the same thing? ... HTML to their students and find it very useful. ... I said was rubbish. ...
    (comp.infosystems.www.authoring.stylesheets)