当前位置: 首页>>代码示例>>C#>>正文


C# HtmlGenericControl.RenderControl方法代码示例

本文整理汇总了C#中HtmlGenericControl.RenderControl方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlGenericControl.RenderControl方法的具体用法?C# HtmlGenericControl.RenderControl怎么用?C# HtmlGenericControl.RenderControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HtmlGenericControl的用法示例。


在下文中一共展示了HtmlGenericControl.RenderControl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderComments

    private string RenderComments(List<Comment> comments, StringDictionary settings)
    {
        if (comments.Count == 0)
        {
            //HttpRuntime.Cache.Insert("widget_recentcomments", "<p>" + Resources.labels.none + "</p>");
            return "<p>" + Resources.labels.none + "</p>";
        }

        HtmlGenericControl ul = new HtmlGenericControl("ul");
        ul.Attributes.Add("class", "recentComments");
        ul.ID = "recentComments";

        foreach (Comment comment in comments)
        {
            if (comment.IsApproved)
            {
                HtmlGenericControl li = new HtmlGenericControl("li");

                // The post title
                HtmlAnchor title = new HtmlAnchor();
                title.HRef = comment.Parent.RelativeLink.ToString();
                title.InnerText = comment.Parent.Title;
                title.Attributes.Add("class", "postTitle");
                li.Controls.Add(title);

                // The comment count on the post
                LiteralControl count = new LiteralControl(" (" + ((Post)comment.Parent).ApprovedComments.Count + ")<br />");
                li.Controls.Add(count);

                // The author
                if (comment.Website != null)
                {
                    HtmlAnchor author = new HtmlAnchor();
                    author.Attributes.Add("rel", "nofollow");
                    author.HRef = comment.Website.ToString();
                    author.InnerHtml = comment.Author;
                    li.Controls.Add(author);

                    LiteralControl wrote = new LiteralControl(" " + Resources.labels.wrote + ": ");
                    li.Controls.Add(wrote);
                }
                else
                {
                    LiteralControl author = new LiteralControl(comment.Author + " " + Resources.labels.wrote + ": ");
                    li.Controls.Add(author);
                }

                // The comment body
                string commentBody = Regex.Replace(comment.Content, @"\[(.*?)\]", "");
                int bodyLength = Math.Min(commentBody.Length, 50);

                commentBody = commentBody.Substring(0, bodyLength);
                if (commentBody.Length > 0)
                {
                    if (commentBody[commentBody.Length - 1] == '&')
                    {
                        commentBody = commentBody.Substring(0, commentBody.Length - 1);
                    }
                }
                commentBody += comment.Content.Length <= 50 ? " " : "... ";
                LiteralControl body = new LiteralControl(commentBody);
                li.Controls.Add(body);

                // The comment link
                HtmlAnchor link = new HtmlAnchor();
                link.HRef = comment.Parent.RelativeLink + "#id_" + comment.Id;
                link.InnerHtml = "[" + Resources.labels.more + "]";
                link.Attributes.Add("class", "moreLink");
                li.Controls.Add(link);

                ul.Controls.Add(li);
            }
        }

        StringWriter sw = new StringWriter();
        ul.RenderControl(new HtmlTextWriter(sw));

        string ahref = "<a href=\"{0}syndication.axd?comments=true\">Comment RSS <img src=\"{0}pics/rssButton.gif\" alt=\"\" /></a>";
        string rss = string.Format(ahref, Utils.RelativeWebRoot);
        sw.Write(rss);
        return sw.ToString();
        //HttpRuntime.Cache.Insert("widget_recentcomments", sw.ToString());
    }
开发者ID:rajgit31,项目名称:RajBlog,代码行数:83,代码来源:widget.ascx.cs


注:本文中的HtmlGenericControl.RenderControl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。