CS Nuglet: Determining first forum thread post for custom UI display

I needed to display a graphic under the user avatar on the first forum thread post today and found it to be an interesting little task.  Essentially I took an approach similar to highlighting an author’s comment in CS2008.5, which I always thought was pretty slick.  You’ll find that on …/hawaii/post.aspx.  Look for IsAuthor().

For our purposes of displaying a graphic in the first forum thread post under the user avatar, we add a Conditional Content control with a custom IsFirstPost() method.

 

<CSControl:ConditionalContent ID=”ConditionalContent1″ runat=”server”>
    <ContentConditions>
       
<CSControl:CustomCondition ID=”CustomCondition1″
            runat=”server” CustomResult='<%# IsFirstPost(Eval(“Subject”)) %>’ />
    </ContentConditions>
    <TrueContentTemplate>
        My cool graphic…
    </TrueContentTemplate>
    <FalseContentTemplate />
</CSControl:ConditionalContent>

 

Our IsFirstPost() method checks if the subject begins with “Re:” to indicate it’s a reply.  I’ve scoured the ForumPost object for a distinct property to use instead, but didn’t find one I liked.  Or else I was approaching it wrong.  Regardless, the subject “Re:” test works just fine.

 

<script runat=”server” language=”C#”>

    bool IsFirstPost(object subject)
    {
        bool isFirstPost = true;
        if (subject.ToString().Substring(0,3) == “Re:”)
            isFirstPost = false;
        return (isFirstPost);
    }

</script>

Now my cool graphic appears under the user avatar of the first forum thread post only.

Article written by

A long time developer, I was an early adopter of Linux in the mid-90's for a few years until I entered corporate environments and worked with Microsoft technologies like ASP, then .NET. In 2008 I released Sueetie, an Online Community Platform built in .NET. In late 2012 I returned to my Linux roots and locked in on Java development. Much of my work is available on GitHub.