locked
Enhancement: Read More link visibility RRS feed

  • Question

  • User-1346905220 posted

    It has always bothered me that for a "short" description, by default 50 words or less, the "read more" link still appears even though there is no more to read. I've come up with a solution that I want to share with anyone who's also annoyed by this. I added two functions to the shared_routines.vb file.

    Public Function HasMore(ByVal originalInput As Object) As Boolean

    Return HasMore(originalInput, TRUNCATE_COUNT)

    End Function

    Public Function HasMore(ByVal originalInput As Object, ByVal wordsLimit As Integer) As Boolean

    If originalInput Is Nothing Or IsDBNull(originalInput) Then

    Return False

    Else

    Dim words() As String = Split(CStr(originalInput))

    If words.Length > wordsLimit Then

    Return True

    Else

    Return False

    End If

    End If

    End Function

    To use these functions, add the visible attribute to the "read more" link on a page as follows.

    <asp:HyperLink ID="newslink" runat="server" NavigateUrl='<%# "news_view.aspx?articleid=" &Cstr( Eval("ID"))%>' visible='<%# hasmore(Eval("description")) %>'>read more &raquo;</asp:HyperLink>

    Some of the "read more" links are actually html anchor tags. You'll need to add a runat="server" attribute to the <a> tag in order to have access to a visible attribute.

    I have a rather limited test environment so if anyone tries this and has trouble, post back and let me know.

    -Mike

    Sunday, July 30, 2006 9:02 PM

All replies

  • User380413204 posted

    Hi Mike,

    Finally got up to implementing this.

    It seems to work fine so far.

    Good job.

    Thanks,

    Lx

    Saturday, August 19, 2006 5:50 PM