<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Keep Your Template Logic in the Template</title>
	<atom:link href="http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/</link>
	<description>News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.</description>
	<pubDate>Tue, 02 Dec 2008 04:57:47 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: Elyzion</title>
		<link>http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-657741</link>
		<dc:creator>Elyzion</dc:creator>
		<pubDate>Thu, 20 Mar 2008 01:20:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-657741</guid>
		<description>&lt;blockquote&gt;Is it really more complex than casting a bunch of controls using FindControl? Especially when some other developer could easily come by, change some ids and break your codebehind bad?&lt;/blockquote&gt;
If another developer breaks your codebehind, he obviously doesn't know what hes doing and therefore shouldn't be developing on your application.

&lt;blockquote&gt;My major new problem with Jonathan Hollands approach was the following line CommentDateTime.Text = currentComment.ShortDateTime;, surely you would consider ShortDateTime to be layout/formatting and it should be in the presentation layer. (although I generally consider the aspx + the aspx.cs the presentation layer and a code library to be the business logic).&lt;/blockquote&gt;

If you want to create this presentation logic so badly, create your own control with a public property for string formatting. Then you can change the property on the control and not have to recompile.

I kinda regret reading this page.</description>
		<content:encoded><![CDATA[<blockquote><p>Is it really more complex than casting a bunch of controls using FindControl? Especially when some other developer could easily come by, change some ids and break your codebehind bad?</p></blockquote>
<p>If another developer breaks your codebehind, he obviously doesn&#8217;t know what hes doing and therefore shouldn&#8217;t be developing on your application.</p>
<blockquote><p>My major new problem with Jonathan Hollands approach was the following line CommentDateTime.Text = currentComment.ShortDateTime;, surely you would consider ShortDateTime to be layout/formatting and it should be in the presentation layer. (although I generally consider the aspx + the aspx.cs the presentation layer and a code library to be the business logic).</p></blockquote>
<p>If you want to create this presentation logic so badly, create your own control with a public property for string formatting. Then you can change the property on the control and not have to recompile.</p>
<p>I kinda regret reading this page.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-511287</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Mon, 26 Nov 2007 11:18:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-511287</guid>
		<description>The way I look at it is to use inline when there is not much logic, codebehind when that becomes ugly (as Wyatt's example did), and a server- or user-control within the template if I am handling too many of the Repeater's events.</description>
		<content:encoded><![CDATA[<p>The way I look at it is to use inline when there is not much logic, codebehind when that becomes ugly (as Wyatt&#8217;s example did), and a server- or user-control within the template if I am handling too many of the Repeater&#8217;s events.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Orbit</title>
		<link>http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-510013</link>
		<dc:creator>Orbit</dc:creator>
		<pubDate>Sun, 25 Nov 2007 21:32:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-510013</guid>
		<description>I'm totally with Jonathan on this - Wyatt you should be more humble in your opinions, especially when theyr'e wrong ;-)</description>
		<content:encoded><![CDATA[<p>I&#8217;m totally with Jonathan on this - Wyatt you should be more humble in your opinions, especially when theyr&#8217;e wrong ;-)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: honeymonster</title>
		<link>http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-509906</link>
		<dc:creator>honeymonster</dc:creator>
		<pubDate>Sun, 25 Nov 2007 20:45:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-509906</guid>
		<description>Well, just forget it then.....</description>
		<content:encoded><![CDATA[<p>Well, just forget it then&#8230;..</p>]]></content:encoded>
	</item>
	<item>
		<title>By: honeymonster</title>
		<link>http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-509902</link>
		<dc:creator>honeymonster</dc:creator>
		<pubDate>Sun, 25 Nov 2007 20:45:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-509902</guid>
		<description>Grrrrrrrr. Sitepoint needs to fix that code block quoting. :-(

Here goes a again:

-------------------------------------------------------------------------

I would prefer:

&lt;code&gt;&#60;asp:ObjectDataSource id="dsComments" TypeName="SitePoint" SelectMethod="GetArticleComments" runat="server"&#62;
    &#60;SelectParameters&#62;
        &#60;asp:QueryStringParameter Type="Int32" Name="articleId" QueryStringField="Id" /&#62;
    &#60;/SelectParameters&#62;
&#60;/asp:ObjectDataSource&#62;
&#60;asp:Repeater runat="server" ID="CommentsRepeater" DataSourceID="dsComments"&#62;
    &#60;HeaderTemplate&#62;
        &#60;ul class="commentcontainer"&#62;
    &#60;/HeaderTemplate&#62;
    &#60;ItemTemplate&#62;
        &#60;li id="Li1" runat="server" visible='&#60;%# !(bool)Eval("IsSuppressed") &#124;&#124; SecurityHelper.CanSeeCommentInfo(User) %&#62;'&#62;
            &#60;p&#62;&#60;%# Eval("CommentText") ?? "no comments . . ." %&#62;&#60;/p&#62;
            &#60;p&#62;By : &#60;a href='&#60;%# Eval("AuthorWeb") %&#62;'&#62;&#60;%# Eval("AuthorName") %&#62;&#60;/a&#62; 
            on &#60;%# Eval("CommentTimeStamp","g") %&#62;&#60;/p&#62;
            &#60;p id="P1" runat="server" visible='&#60;%# User.CanSeeCommentInfo() %&#62;'&#62;
                &#60;a href='mailto:&#60;%# Eval("AuthorEmail") %&#62;'&#62;&#60;%# Eval("AuthorEmail") %&#62;&#60;/a&#62;
                • IP:
                &#60;%# Eval("AuthorIpAddress") %&#62;
                &#60;asp:LinkButton runat="server" ID="SuppressCommentButton" CommandArgument='&#60;%# Eval("Id") %&#62;'
                    Text='[Suppress Comment]' Visible='&#60;%# !(bool)Eval("IsSuppressed") &#38;&#38; User.CanSuppressComment() %&#62;'
                    OnClick="DoSuppressComment" /&#62;
            &#60;/p&#62;
        &#60;/li&#62;
    &#60;/ItemTemplate&#62;
    &#60;FooterTemplate&#62;
        &#60;/ul&#62;
    &#60;/FooterTemplate&#62;
&#60;/asp:Repeater&#62;&lt;/code&gt;

This would have to be backed by some extension methods (C# 3.0):

&lt;code&gt;
    public static class SecurityHelper
    {
        public static bool CanSeeCommentInfo(this IPrincipal user) {
            throw new NotImplementedException();
        }

        public static bool CanSuppressComment(this IPrincipal user)
        {
            throw new NotImplementedException();
        }
    }&lt;/code&gt;

In the real MVC, the view goes to the model directly. That is implemented by an object datasource which can be a static facade or another object with default constructor which reads its conf. from the conf file.

I use Eval since it allows a much shorter notation. I also import the namespaces so that I don't need Wyatts long paths.

Really the only thing needed to be implemented in the codebehind here is the actions, such as DoSuppressComments. This allows you (or designer) to change the page, possibly pulling in more entities using another objectdatasource, without touching the codebehind.

Wyatt is right that Eval uses reflection internally and thus is slightly (!) slower than direct access. However, with the number of typecasts in your example, I'm not so certain that is would in fact be faster. Anyhow, this is negligible.

The real problems here is that we are being let down by the MS ASP.NET team. C# got generics in C# 2.0, but the templates of ASP.NET still just assumes dataitems are objects. IMO repeaters and other data aware controls should expose a generic Item property method that - when bound to a statically typed datasource - exposed the item as statically typed.

Also, I would like to see a generic version of FindControl, enabling me to write FindControl&#60;TextBox&#62;("Name") - and use it strongly typed.</description>
		<content:encoded><![CDATA[<p>Grrrrrrrr. Sitepoint needs to fix that code block quoting. :-(</p>
<p>Here goes a again:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>I would prefer:</p>
<code>&lt;asp:ObjectDataSource id="dsComments" TypeName="SitePoint" SelectMethod="GetArticleComments" runat="server"&gt;
    &lt;SelectParameters&gt;
        &lt;asp:QueryStringParameter Type="Int32" Name="articleId" QueryStringField="Id" /&gt;
    &lt;/SelectParameters&gt;
&lt;/asp:ObjectDataSource&gt;
&lt;asp:Repeater runat="server" ID="CommentsRepeater" DataSourceID="dsComments"&gt;
    &lt;HeaderTemplate&gt;
        &lt;ul class="commentcontainer"&gt;
    &lt;/HeaderTemplate&gt;
    &lt;ItemTemplate&gt;
        &lt;li id="Li1" runat="server" visible='&lt;%# !(bool)Eval("IsSuppressed") || SecurityHelper.CanSeeCommentInfo(User) %&gt;'&gt;
            &lt;p&gt;&lt;%# Eval("CommentText") ?? "no comments . . ." %&gt;&lt;/p&gt;
            &lt;p&gt;By : &lt;a href='&lt;%# Eval("AuthorWeb") %&gt;'&gt;&lt;%# Eval("AuthorName") %&gt;&lt;/a&gt; 
            on &lt;%# Eval("CommentTimeStamp","g") %&gt;&lt;/p&gt;
            &lt;p id="P1" runat="server" visible='&lt;%# User.CanSeeCommentInfo() %&gt;'&gt;
                &lt;a href='mailto:&lt;%# Eval("AuthorEmail") %&gt;'&gt;&lt;%# Eval("AuthorEmail") %&gt;&lt;/a&gt;
                • IP:
                &lt;%# Eval("AuthorIpAddress") %&gt;
                &lt;asp:LinkButton runat="server" ID="SuppressCommentButton" CommandArgument='&lt;%# Eval("Id") %&gt;'
                    Text='[Suppress Comment]' Visible='&lt;%# !(bool)Eval("IsSuppressed") &amp;&amp; User.CanSuppressComment() %&gt;'
                    OnClick="DoSuppressComment" /&gt;
            &lt;/p&gt;
        &lt;/li&gt;
    &lt;/ItemTemplate&gt;
    &lt;FooterTemplate&gt;
        &lt;/ul&gt;
    &lt;/FooterTemplate&gt;
&lt;/asp:Repeater&gt;</code>
<p>This would have to be backed by some extension methods (C# 3.0):</p>
<code>
    public static class SecurityHelper
    {
        public static bool CanSeeCommentInfo(this IPrincipal user) {
            throw new NotImplementedException();
        }

        public static bool CanSuppressComment(this IPrincipal user)
        {
            throw new NotImplementedException();
        }
    }</code>
<p>In the real MVC, the view goes to the model directly. That is implemented by an object datasource which can be a static facade or another object with default constructor which reads its conf. from the conf file.</p>
<p>I use Eval since it allows a much shorter notation. I also import the namespaces so that I don&#8217;t need Wyatts long paths.</p>
<p>Really the only thing needed to be implemented in the codebehind here is the actions, such as DoSuppressComments. This allows you (or designer) to change the page, possibly pulling in more entities using another objectdatasource, without touching the codebehind.</p>
<p>Wyatt is right that Eval uses reflection internally and thus is slightly (!) slower than direct access. However, with the number of typecasts in your example, I&#8217;m not so certain that is would in fact be faster. Anyhow, this is negligible.</p>
<p>The real problems here is that we are being let down by the MS ASP.NET team. C# got generics in C# 2.0, but the templates of ASP.NET still just assumes dataitems are objects. IMO repeaters and other data aware controls should expose a generic Item property method that - when bound to a statically typed datasource - exposed the item as statically typed.</p>
<p>Also, I would like to see a generic version of FindControl, enabling me to write FindControl&lt;TextBox&gt;(&#8221;Name&#8221;) - and use it strongly typed.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: honeymonster</title>
		<link>http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-509881</link>
		<dc:creator>honeymonster</dc:creator>
		<pubDate>Sun, 25 Nov 2007 20:37:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-509881</guid>
		<description>I would prefer:

&lt;code&gt;
    
        
    


    
        
    
    
        '&#62;
            
            By : &lt;a&gt;'&#62;&lt;/a&gt; 
            on 
            '&#62;
                &lt;a&gt;'&#62;&lt;/a&gt;
                • IP:
                
                '
                    Text='[Suppress Comment]' Visible=''
                    OnClick="DoSuppressComment" /&#62;
            
        
    
    
        
    
&lt;/code&gt;

This would have to be backed by some extension methods:

&lt;code&gt;
    public static class SecurityHelper
    {
        public static bool CanSeeCommentInfo(this IPrincipal user) {
            throw new NotImplementedException();
        }

        public static bool CanSuppressComment(this IPrincipal user)
        {
            throw new NotImplementedException();
        }
    }
&lt;/code&gt;

In the real MVC, the view goes to the model directly. That is implemented by an object datasource which can be a static facade or another object with default contructor which reads its conf. from the conf file.

I use Eval since it allows a much shorter notation. I also import the namespaces so that I don't need wyatt's long paths.

Really the only thing needed to be implemented in the codebehind here is the actions, such as DoSuppressComments. This allows you (or designer) to change the page, possibly pulling in more entities using another objectdatasource, without touching the codebehind.

Wyatt is right that Eval uses reflection internally and thus is slightly (!) slower than direct access. However, with the number of typecasts in your example, I'm not so certain that is would in fact be faster. Anyhow, this is negligible.

The real problems here is that we are being let down by the MS ASP.NET team. C# got generics in C# 2.0, but the templates of ASP.NET still just assumes dataitems are objects. IMO repeaters and other data aware controls should expose a generic Item property method that - when bound to a statically typed datasource - exposed the item as statically typed.

Also, I would like to see a generic version of FindControl, enabling me to write FindControl("Name") - and use it strongly typed.</description>
		<content:encoded><![CDATA[<p>I would prefer:</p>
<code>
    
        
    


    
        
    
    
        '&gt;
            
            By : <a>'&gt;</a> 
            on 
            '&gt;
                <a>'&gt;</a>
                • IP:
                
                '
                    Text='[Suppress Comment]' Visible=''
                    OnClick="DoSuppressComment" /&gt;
            
        
    
    
        
    
</code>
<p>This would have to be backed by some extension methods:</p>
<code>
    public static class SecurityHelper
    {
        public static bool CanSeeCommentInfo(this IPrincipal user) {
            throw new NotImplementedException();
        }

        public static bool CanSuppressComment(this IPrincipal user)
        {
            throw new NotImplementedException();
        }
    }
</code>
<p>In the real MVC, the view goes to the model directly. That is implemented by an object datasource which can be a static facade or another object with default contructor which reads its conf. from the conf file.</p>
<p>I use Eval since it allows a much shorter notation. I also import the namespaces so that I don&#8217;t need wyatt&#8217;s long paths.</p>
<p>Really the only thing needed to be implemented in the codebehind here is the actions, such as DoSuppressComments. This allows you (or designer) to change the page, possibly pulling in more entities using another objectdatasource, without touching the codebehind.</p>
<p>Wyatt is right that Eval uses reflection internally and thus is slightly (!) slower than direct access. However, with the number of typecasts in your example, I&#8217;m not so certain that is would in fact be faster. Anyhow, this is negligible.</p>
<p>The real problems here is that we are being let down by the MS ASP.NET team. C# got generics in C# 2.0, but the templates of ASP.NET still just assumes dataitems are objects. IMO repeaters and other data aware controls should expose a generic Item property method that - when bound to a statically typed datasource - exposed the item as statically typed.</p>
<p>Also, I would like to see a generic version of FindControl, enabling me to write FindControl(&#8221;Name&#8221;) - and use it strongly typed.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: goykanok</title>
		<link>http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-508080</link>
		<dc:creator>goykanok</dc:creator>
		<pubDate>Sun, 25 Nov 2007 07:47:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-508080</guid>
		<description>The jolly website, more with &lt;a href="http://www.googleandme.com" rel="nofollow"&gt;googleandme&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>The jolly website, more with <a href="http://www.googleandme.com" rel="nofollow">googleandme</a>.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Holland</title>
		<link>http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-507099</link>
		<dc:creator>Jonathan Holland</dc:creator>
		<pubDate>Sat, 24 Nov 2007 22:54:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-507099</guid>
		<description>Betty:

Comment.ShortDateTime is just a property that returns a string in the business layer. Instead of returning a DateTime Object and having to cast it to a string, its easier to have an additional property in the BLL. Why repeat yourself? :)

I find fault with ASP.NET and nested controls. They should be exposed strongly typed, yet they are not, hence the need for FindControl. If you spend any time at all writing custom controls in ASP.NET you will find that you need to use FindControl. It is a necessary evil.</description>
		<content:encoded><![CDATA[<p>Betty:</p>
<p>Comment.ShortDateTime is just a property that returns a string in the business layer. Instead of returning a DateTime Object and having to cast it to a string, its easier to have an additional property in the BLL. Why repeat yourself? :)</p>
<p>I find fault with ASP.NET and nested controls. They should be exposed strongly typed, yet they are not, hence the need for FindControl. If you spend any time at all writing custom controls in ASP.NET you will find that you need to use FindControl. It is a necessary evil.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Betty</title>
		<link>http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-507088</link>
		<dc:creator>Betty</dc:creator>
		<pubDate>Sat, 24 Nov 2007 22:49:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-507088</guid>
		<description>Damnit. I'm just gonna let someone clean that up, the idea wasn't that exciting anyway.  I guess if I could be bothered registering I could probably have just edited my comments.  &#60;asp:repeater&#60;SitePoint.Core.Entities.Content.ArticleComment&#62;&#62;</description>
		<content:encoded><![CDATA[<p>Damnit. I&#8217;m just gonna let someone clean that up, the idea wasn&#8217;t that exciting anyway.  I guess if I could be bothered registering I could probably have just edited my comments.  &lt;asp:repeater&lt;SitePoint.Core.Entities.Content.ArticleComment&gt;&gt;</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Betty</title>
		<link>http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-507071</link>
		<dc:creator>Betty</dc:creator>
		<pubDate>Sat, 24 Nov 2007 22:46:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/2007/11/25/keep-your-template-logic-in-the-template/#comment-507071</guid>
		<description>Ah the joy of blog formatting, looks like I mananged to mangle the end of my comment there quite nicely.


All that casting in the aspx is quite ugly, strongly typed repeaters would be a really nice thing.

&lt;code&gt;
  
    
      
  ...
&lt;/code&gt;

Pity you can’t nicely use generics &lt;code&gt;&#62;&lt;/code&gt;?</description>
		<content:encoded><![CDATA[<p>Ah the joy of blog formatting, looks like I mananged to mangle the end of my comment there quite nicely.</p>
<p>All that casting in the aspx is quite ugly, strongly typed repeaters would be a really nice thing.</p>
<code>
  
    
      
  ...
</code>
<p>Pity you can’t nicely use generics <code>&gt;</code>?</p>]]></content:encoded>
	</item>
</channel>
</rss>
