public string AjaxExpand(string id)
        {
            bool isLastNode = Request.Form["IsLastNode"].Cast<bool>(false);
            AjaxTreeNodeCollection ajaxTreeNodes = getChildrenNodes(id);
            ajaxTreeNodes.Owner = AjaxTree1;
            ajaxTreeNodes.NodesState = NodeState.Open;
            Html32TextWriter writer = new Html32TextWriter(Response.Output);
            ajaxTreeNodes.AjaxRender(writer, 1, isLastNode);

            return string.Empty;
        }
示例#2
0
 public void ExportExcel(DataGrid SeriesValuesDataGrid)
 {
     System.Web.UI.Control ctl = new System.Web.UI.Control();
     HttpContext.Current.Response.ContentType = "application/ms-Excel";
     HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=data.xls");
     System.IO.StringWriter         tw = new System.IO.StringWriter();
     System.Web.UI.Html32TextWriter hw = new System.Web.UI.Html32TextWriter(tw);
     ctl.EnableViewState = false;
     SeriesValuesDataGrid.RenderControl(hw);
     HttpContext.Current.Response.Write(tw.ToString());
     HttpContext.Current.Response.End();
 }
示例#3
0
        private string RenderControl(UserControl control)
        {
            StringBuilder sb = new StringBuilder();

            // Render the control into the stringbuilder
            StringWriter sw = new StringWriter( sb );
            Html32TextWriter htw = new Html32TextWriter( sw );
            control.RenderControl( htw );

            // Get full body text
            return sb.ToString();
        }
        public static string RenderControl(Control control)
        {
            var tw = new StringWriter();

            // *** Simple rendering - just write the control to the text writer
            // *** works well for single controls without containers
            var writer = new Html32TextWriter(tw);
            control.RenderControl(writer);
            writer.Close();

            return tw.ToString();
        }
示例#5
0
		private void Deny_Unrestricted (Html32TextWriter htw)
		{
			htw.ShouldPerformDivTableSubstitution = true;
			Assert.IsTrue (htw.ShouldPerformDivTableSubstitution, "ShouldPerformDivTableSubstitution");
			htw.SupportsBold = true;
			Assert.IsTrue (htw.SupportsBold, "SupportsBold");
			htw.SupportsItalic = true;
			Assert.IsTrue (htw.SupportsItalic, "SupportsItalic");
			htw.RenderBeginTag (HtmlTextWriterTag.Table);
			htw.RenderBeginTag ("<tr>");
			htw.RenderEndTag ();
		}
示例#6
0
 public static HelperResult DraftIcon(this HtmlHelper html, ContentDataItemDecorator dataItem)
 {
     return new HelperResult((w) =>
     {
         using (var writer = new Html32TextWriter(w))
         {
             if (!dataItem.IsPublished)
             {
                 writer.WriteBeginTag("span");
                 writer.WriteAttribute("title", "Draft");
                 writer.WriteAttribute("class", "d-icon d-icon-draft");
                 writer.Write(HtmlTextWriter.TagRightChar);
                 writer.WriteEndTag("span");
             }
         }
     });
 }
示例#7
0
 public static HelperResult AttachIcon(this HtmlHelper html, ContentDataItemDecorator dataItem)
 {
     return new HelperResult((w) =>
     {
         using (var writer = new Html32TextWriter(w))
         {
             if (dataItem.HasAttachments)
             {
                 var url = new UrlHelper(html.ViewContext.RequestContext);
                 writer.WriteBeginTag("a");
                 writer.WriteAttribute("href", url.Content(dataItem) + "#attachments");
                 writer.WriteAttribute("class", "d-icon d-icon-attach");
                 writer.Write(HtmlTextWriter.TagRightChar);
                 writer.WriteEndTag("a");
             }
         }
     });
 }
示例#8
0
        private string CreateBody( string userName, string password )
        {
            StringBuilder sb = new StringBuilder();

            // Load the control
            ForgotEmail ctrl = (ForgotEmail)LoadControl( "~/Controls/Templates/ForgotEmail.ascx" );

            ctrl.UserName = userName;
            ctrl.Password = password;
            ctrl.SetProperties();

            // Render the control into the stringbuilder
            StringWriter sw = new StringWriter( sb );
            Html32TextWriter htw = new Html32TextWriter( sw );
            ctrl.RenderControl( htw );

            // Get full body text
            return sb.ToString();
        }
示例#9
0
 /// <summary>
 ///  Render the webpage onto the give specified engine. 
 /// </summary>
 /// <param name='serverFolder'>
 /// The root of the folder of the web server.
 /// </param>
 /// <param name='engine'>
 ///  The given specified engine. 
 /// </param>
 /// <param name='writer'>
 /// The html writer to write content to.
 /// </param>
 public virtual void Render(string serverFolder, HttpEngine engine, Html32TextWriter writer)
 {
     this.Load (serverFolder);
     if (this.pieces != null) {
         foreach (IWebPagePiece piece in this.Pieces) {
             piece.Render (serverFolder, engine, writer);
         }
     }
 }
示例#10
0
 /// <summary>
 /// Writes references of some javascript libraries to the given <see cref="Html32TextWriter"/> to let the bootstrap work.
 /// </summary>
 /// <param name='htw'>
 /// The <see cref="Html32TextWriter"/> to write the content to.
 /// </param>
 private void WriteJavascript(Html32TextWriter htw)
 {
     htw.AddAttribute (HtmlTextWriterAttribute.Src, "http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js");
     htw.RenderBeginTag (HtmlTextWriterTag.Script);
     htw.RenderEndTag ();
     htw.WriteLine ();
     htw.AddAttribute (HtmlTextWriterAttribute.Src, "http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js");
     htw.RenderBeginTag (HtmlTextWriterTag.Script);
     {}
     htw.RenderEndTag ();
 }
示例#11
0
 /// <summary>
 /// Writes a footer of every webpage to the given <see cref="Html32TextWriter"/> instance.
 /// </summary>
 /// <param name='htw'>
 /// The <see cref="Html32TextWriter"/> to write the webpage to.
 /// </param>
 private void WriteFooter(Html32TextWriter htw)
 {
     htw.RenderBeginTag (HtmlTextWriterTag.Hr);
     htw.RenderEndTag ();
     htw.AddAttribute (HtmlTextWriterAttribute.Class, "footer");
     htw.RenderBeginTag (HtmlTextWriterTag.Div);
     htw.RenderBeginTag (HtmlTextWriterTag.P);
     htw.Write ("This page is created with {0}", ProgramManager.ProgramNameVersion);
     htw.RenderEndTag ();
     htw.RenderEndTag ();
 }
示例#12
0
        /// <summary>
        /// Converts the set of <see cref="IdpGie.Shapes.IShape"/> by converting it into a readable format.
        /// </summary>
        public override void Process()
        {
            using (StreamReader inputStream = new StreamReader (client.GetStream ())) {
                String request = inputStream.ReadLine (), line;
                string[] tokens = request.Split (' ');
                if (tokens.Length != 3) {
                    throw new Exception ("invalid http request line");
                }
                StringBuilder rest = new StringBuilder ();
                do {
                    line = inputStream.ReadLine ();
                    rest.AppendLine (line);
                } while(line != string.Empty && line != null);
                //string http_url = tokens [1];
                string http_filename = tokens [1];
                Console.WriteLine ("\"{0}\"", http_filename);

                if (http_filename == "/" + IconName) {
                    this.device.Navigationbar.FavIcon.RenderIcon (this.device.Manager.ServerFolder, this, client.GetStream ());
                } else {
                    bool border;
                    IWebPage wp = this.device.Navigationbar.GetPage (http_filename.Substring (0x01), out border);
                    using (StreamWriter sw = new StreamWriter (client.GetStream ())) {
                        using (Html32TextWriter tw = new Html32TextWriter (sw)) {
                            if (border) {
                                tw.WriteLine ("<!DOCTYPE html>");
                                tw.RenderBeginTag (HtmlTextWriterTag.Html);
                                tw.RenderBeginTag (HtmlTextWriterTag.Head);
                                this.WriteHeader (tw);
                                tw.RenderEndTag ();
                                tw.RenderBeginTag (HtmlTextWriterTag.Body);
                                this.WriteBody (tw, wp);
                                this.WriteJavascript (tw);
                                tw.RenderEndTag ();
                                tw.RenderEndTag ();
                            } else {
                                wp.Render (this.device.Manager.ServerFolder, this, tw);
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Render the webpage onto the give specified engine.
 /// </summary>
 /// <param name="serverFolder">The root of the folder of the web server.</param>
 /// <param name="engine">The given specified engine.</param>
 /// <param name="writer">The html writer to write content to.</param>
 /// <remarks>
 /// <para>This method should be overridden with the query answer.</para>
 /// </remarks>
 public virtual void Render(string serverFolder, HttpEngine engine, Html32TextWriter writer)
 {
 }
示例#14
0
		public void Ctor1_Deny_Unrestricted ()
		{
			Html32TextWriter htw = new Html32TextWriter (sw);
			Deny_Unrestricted (htw);
		}
示例#15
0
        /// <summary>
        /// Generate validation data attributes for TextField object.
        /// </summary>
        /// <param name="field">The TextField object.</param>
        /// <returns></returns>
        public static HelperResult GetValidationAttributes(this TextField field)
        {
            string ValidationErrorIncludingMinimum = "The {0} must be a string with a minimum length of {2} and a maximum length of {1}.";
            string StringLengthAttribute_ValidationError = "The {0} must be a string with a maximum length of {1}.";

            return new HelperResult((w) =>
            {
                using (var writer = new Html32TextWriter(w))
                {
                    if (field.MaxLength > 0 || field.MinLength > 0 || field.IsRequired)
                    {
                        writer.WriteAttribute("data-val", "true");
                        writer.WriteAttribute("data-val-required", string.Format(RES_REQURIED, field.Title));
                        if (field.MaxLength > 0 && field.MinLength > 0)
                        {
                            writer.WriteAttribute("data-val-length", string.Format(ValidationErrorIncludingMinimum, field.MinLength, field.MinLength));
                            writer.WriteAttribute("data-val-length-max", field.MaxLength.ToString());
                            writer.WriteAttribute("data-val-length-min", field.MinLength.ToString());
                        }
                        else
                        {
                            if (field.MaxLength > 0)
                            {
                                writer.WriteAttribute("data-val-length-max", field.MaxLength.ToString());
                                writer.WriteAttribute("data-val-length", string.Format(StringLengthAttribute_ValidationError, field.MaxLength));
                            }
                        }
                    }
                }
            });
        }
示例#16
0
 /// <summary>
 ///  Render the webpage onto the give specified engine. 
 /// </summary>
 /// <param name='serverFolder'>
 ///  The root of the folder of the web server. 
 /// </param>
 /// <param name='engine'>
 ///  The given specified engine. 
 /// </param>
 /// <param name='writer'>
 ///  The html writer to write content to. 
 /// </param>
 public abstract void Render(string serverFolder, HttpEngine engine, Html32TextWriter writer);
示例#17
0
        /// <summary>
        /// Generate validation data attributes for CurrentField object.
        /// </summary>
        /// <param name="field">The CurrencyField object.</param>
        /// <returns></returns>
        public static HelperResult GetValidationAttributes(this CurrencyField field)
        {
            return new HelperResult((w) =>
            {
                using (var writer = new Html32TextWriter(w))
                {
                    writer.WriteAttribute("data-val", "true");
                    writer.WriteAttribute("data-val-number", string.Format("The {0} must be a vaild number.", field.Title));
                    //if (field.DecimalDigits > 0)
                    //    writer.WriteAttribute("data-val-digits", string.Format("The {0} must be have {1} digits.", field.Title, field.DecimalDigits));

                    if (field.MaximumValue > 0 || field.MaximumValue > 0 || field.IsRequired)
                    {

                        writer.WriteAttribute("data-val-required", string.Format(RES_REQURIED, field.Title));
                        if (field.MaximumValue > 0 && field.MaximumValue > 0)
                        {
                            writer.WriteAttribute("data-val-range", string.Format(RangeAttribute_ValidationError, field.MaximumValue, field.MaximumValue));
                            writer.WriteAttribute("data-val-range-max", field.MaximumValue.ToString());
                            writer.WriteAttribute("data-val-range-min", field.MaximumValue.ToString());
                        }
                        else
                        {
                            if (field.MaximumValue > 0)
                            {
                                writer.WriteAttribute("data-val-range", string.Format(RangeAttribute_Max, field.MaximumValue));
                                writer.WriteAttribute("data-val-range-max", field.MaximumValue.ToString());
                            }

                            if (field.MinimumValue > 0)
                            {
                                writer.WriteAttribute("data-val-range", string.Format(RangeAttribute_Min, field.MinimumValue));
                                writer.WriteAttribute("data-val-range-min", field.MinimumValue.ToString());
                            }
                        }
                    }
                }
            });
        }
示例#18
0
		public void Ctor2_Deny_Unrestricted ()
		{
			Html32TextWriter htw = new Html32TextWriter (sw, String.Empty);
			Deny_Unrestricted (htw);
		}
示例#19
0
 /// <summary>
 /// Render hidden input element for field value.
 /// </summary>
 /// <param name="html">The html helper object.</param>
 /// <param name="field">The field object</param>
 /// <param name="value">the field value</param>
 /// <returns></returns>
 public static HelperResult Hidden(this HtmlHelper html, ContentField field, object value = null)
 {
     return new HelperResult((w) =>
     {
         using (var writer = new Html32TextWriter(w))
         {
             writer.WriteBeginTag("input");
             writer.WriteAttribute("type", "hidden");
             writer.WriteAttribute("id", field.ClientID);
             writer.WriteAttribute("name", field.Name);
             if (value != null)
             {
                 writer.WriteAttribute("value", value.ToString());
             }
             else
             {
                 if (field.DefaultValue != null)
                     writer.WriteAttribute("value", field.DefaultValue.ToString());
             }
             writer.Write(HtmlTextWriter.SelfClosingTagEnd);
         }
     });
 }
示例#20
0
 /// <summary>
 ///  Render the webpage onto the give specified engine. 
 /// </summary>
 /// <param name='serverFolder'>
 ///  The root of the folder of the web server. 
 /// </param>
 /// <param name='engine'>
 ///  The given specified engine. 
 /// </param>
 /// <param name='writer'>
 ///  The html writer to write content to. 
 /// </param>
 public override void Render(string serverFolder, HttpEngine engine, Html32TextWriter writer)
 {
     writer.Write (this.fragment);
 }
示例#21
0
        /// <summary>
        /// Render html element for specified field object.
        /// </summary>
        /// <param name="html">The html helper object.</param>
        /// <param name="field">The field object</param>
        /// <returns></returns>
        public static HelperResult Label(this HtmlHelper html, ContentField field)
        {
            return new HelperResult((w) =>
            {
                using (var writer = new Html32TextWriter(w))
                {
                    try
                    {
                        writer.WriteBeginTag("label");
                        writer.WriteAttribute("for", field.ClientID);
                        writer.Write(HtmlTextWriter.TagRightChar);
                        if (!string.IsNullOrEmpty(field.Title))
                            writer.WriteEncodedText(field.Title);
                        else
                            writer.WriteEncodedText(field.Name);
                        writer.WriteEndTag("label");
                    }
                    catch
                    {

                    }
                }
            });
        }
示例#22
0
        /// <summary>
        /// Writes the body of the given <see cref="IWebPage"/> to the <see cref="Html32TextWriter"/>.
        /// </summary>
        /// <param name='htw'>
        /// The <see cref="Html32TextWriter"/> to write the content to.
        /// </param>
        /// <param name='webpage'>
        /// The <see cref="IWebPage"/> to write to the <see cref="Html32TextWriter"/>.
        /// </param>
        private void WriteBody(Html32TextWriter htw, IWebPage webpage)
        {
            this.WriteMasthead (htw, webpage);
            htw.AddAttribute (HtmlTextWriterAttribute.Class, "container");
            htw.RenderBeginTag (HtmlTextWriterTag.Div);
            htw.RenderBeginTag (HtmlTextWriterTag.Hr);
            htw.RenderEndTag ();

            webpage.Render (this.device.Manager.ServerFolder, this, htw);

            this.WriteFooter (htw);
            htw.RenderEndTag ();
        }
示例#23
0
        public static HelperResult ModerateStatus(this HtmlHelper html, ContentDataItemDecorator dataItem)
        {
            return new HelperResult((w) =>
            {
                using (var writer = new Html32TextWriter(w))
                {
                    writer.WriteBeginTag("span");
                    writer.Write(HtmlTextWriter.TagRightChar);
                    if (dataItem.IsPublished)
                    {
                        if (dataItem.Parent.IsModerated)
                        {
                            var state = (ModerateStates)dataItem.ModerateState;
                            switch (state)
                            {
                                case ModerateStates.Pending:
                                    writer.Write("Pending review");
                                    break;
                                case ModerateStates.Rejected:
                                    writer.Write("Rejected");
                                    break;
                                default:
                                    writer.Write("Published");
                                    break;
                            }
                        }
                        else
                            writer.Write("Published");
                    }
                    else
                        writer.Write("Draft");

                    writer.WriteEndTag("span");
                }
            });
        }
示例#24
0
 /// <summary>
 /// Writes the header of the webpage. The header contains references to bootstrap, a favoicon and some stylefile.
 /// </summary>
 /// <param name='htw'>
 /// A <see cref="Html32TextWriter"/> to write the content to.
 /// </param>
 private void WriteHeader(Html32TextWriter htw)
 {
     htw.RenderBeginTag (HtmlTextWriterTag.Title);
     {
         htw.Write (this.device.Navigationbar.Name);
     }
     htw.RenderEndTag ();
     htw.AddAttribute (HtmlTextWriterAttribute.Name, "generator");
     htw.AddAttribute (HtmlTextWriterAttribute.Content, ProgramManager.ProgramNameVersion);
     htw.RenderBeginTag (HtmlTextWriterTag.Meta);
     {}
     htw.RenderEndTag ();
     htw.WriteLine ();
     htw.AddAttribute (HtmlTextWriterAttribute.Name, "viewport");
     htw.AddAttribute (HtmlTextWriterAttribute.Content, "width=device-width, initial-scale=1.0");
     htw.RenderBeginTag (HtmlTextWriterTag.Meta);
     {}
     htw.RenderEndTag ();
     htw.WriteLine ();
     htw.AddAttribute (HtmlTextWriterAttribute.Href, "http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css");
     htw.AddAttribute (HtmlTextWriterAttribute.Rel, "stylesheet");
     htw.RenderBeginTag (HtmlTextWriterTag.Link);
     {}
     htw.RenderEndTag ();
     htw.WriteLine ();
     htw.AddAttribute (HtmlTextWriterAttribute.Href, IconName);
     htw.AddAttribute (HtmlTextWriterAttribute.Rel, "icon");
     htw.AddAttribute (HtmlTextWriterAttribute.Type, "image/x-icon");
     htw.RenderBeginTag (HtmlTextWriterTag.Link);
     {}
     htw.RenderEndTag ();
     htw.WriteLine ();
     htw.RenderBeginTag (HtmlTextWriterTag.Style);
     {
         htw.Write ("body {min-height: 2000px;padding-top: 70px;}");
     }
     htw.RenderEndTag ();
     htw.AddAttribute ("language", "javascript");
     htw.RenderBeginTag (HtmlTextWriterTag.Script);
     {
         htw.WriteLine ("function genericAjax (source, target) {");
         htw.WriteLine ("    var xmlhttp;");
         htw.WriteLine ("    if (window.XMLHttpRequest) {");
         htw.WriteLine ("        xmlhttp=new XMLHttpRequest();");
         htw.WriteLine ("    } else {");
         htw.WriteLine ("        xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\");");
         htw.WriteLine ("    }");
         htw.WriteLine ("    xmlhttp.onreadystatechange=function() {");
         htw.WriteLine ("        if (xmlhttp.readyState==4) {");
         htw.WriteLine ("            if(xmlhttp.status==200) {");
         htw.WriteLine ("                document.getElementById(target).innerHTML=xmlhttp.responseText;");
         htw.WriteLine ("            } else {");
         htw.WriteLine ("                document.getElementById(target).innerHTML=\"<div class='alert alert-warning'><strong>Warning:</strong> something went wrong during an AJAX call. Error code: \"+xmlhttp.status+\", Source: \"+source+\".</div>\";");
         htw.WriteLine ("            }");
         htw.WriteLine ("        }");
         htw.WriteLine ("    }");
         htw.WriteLine ("    xmlhttp.open(\"GET\",source,true);");
         htw.WriteLine ("    xmlhttp.send();");
         htw.WriteLine ("}");
     }
     htw.RenderEndTag ();
     htw.WriteLine ();
 }
示例#25
0
 public static HelperResult NewStatus(this HtmlHelper html, ContentDataItemDecorator dataItem)
 {
     return new HelperResult((w) =>
     {
         using (var writer = new Html32TextWriter(w))
         {
             if (dataItem.IsNew)
             {
                 writer.WriteBeginTag("sup");
                 //writer.WriteAttribute("for", field.ClientID);
                 writer.Write(HtmlTextWriter.TagRightChar);
                 writer.Write("new");
                 //writer.WriteEncodedText(field.Title);
                 writer.WriteEndTag("sup");
             }
         }
     });
 }
示例#26
0
 /// <summary>
 /// Writes the navigation bar to the given <see cref="Html32TextWriter"/>.
 /// </summary>
 /// <param name='htw'>
 /// The <see cref="Html32TextWriter"/> to write the content to.
 /// </param>
 /// <param name='webpage'>
 /// The webpage that is currently displayed. This is needed to denote the current page.
 /// </param>
 private void WriteMasthead(Html32TextWriter htw, IWebPage webpage)
 {
     INavbar navbar = this.device.Navigationbar;
     htw.AddAttribute (HtmlTextWriterAttribute.Class, "navbar navbar-default navbar-fixed-top");
     htw.AddAttribute ("role", "navigation");
     htw.RenderBeginTag (HtmlTextWriterTag.Div);
     {
         htw.AddAttribute (HtmlTextWriterAttribute.Class, "container-fluid");
         htw.RenderBeginTag (HtmlTextWriterTag.Div);
         {
             htw.AddAttribute (HtmlTextWriterAttribute.Class, "navbar-header");
             htw.RenderBeginTag (HtmlTextWriterTag.Div);
             {
                 htw.AddAttribute (HtmlTextWriterAttribute.Class, "navbar-brand");
                 htw.AddAttribute (HtmlTextWriterAttribute.Href, "#");
                 htw.RenderBeginTag (HtmlTextWriterTag.A);
                 {
                     htw.Write (navbar.Name);
                 }
                 htw.RenderEndTag ();
             }
             htw.RenderEndTag ();
             htw.AddAttribute (HtmlTextWriterAttribute.Class, "navbar-collapse collapse");
             htw.RenderBeginTag (HtmlTextWriterTag.Div);
             {
                 htw.AddAttribute (HtmlTextWriterAttribute.Class, "nav navbar-nav");
                 htw.RenderBeginTag (HtmlTextWriterTag.Ul);
                 {
                     foreach (IWebPage wp in navbar.Pages) {
                         if (wp == webpage) {
                             htw.AddAttribute (HtmlTextWriterAttribute.Class, "active");
                         }
                         htw.RenderBeginTag (HtmlTextWriterTag.Li);
                         htw.AddAttribute (HtmlTextWriterAttribute.Href, wp.Href);
                         htw.RenderBeginTag (HtmlTextWriterTag.A);
                         htw.Write (wp.Name);
                         htw.RenderEndTag ();
                         htw.RenderEndTag ();
                     }
                 }
                 htw.RenderEndTag ();
             }
             htw.RenderEndTag ();
         }
         htw.RenderEndTag ();
     }
     htw.RenderEndTag ();
 }
示例#27
0
        /// <summary>
        /// ajax输出
        /// </summary>
        /// <returns></returns>
        public string AjaxRender()
        {
            StringBuilder sb = new StringBuilder();
            using (System.IO.StringWriter sw = new System.IO.StringWriter(sb))
            using (Html32TextWriter hw = new Html32TextWriter(sw))
            {
                RenderBeginTag(hw);
                HeaderRow.RenderControl(hw);
                foreach (GridViewRow row in Rows)
                {
                    row.RenderControl(hw);
                }
                FooterRow.RenderControl(hw);
                RenderEndTag(hw);
            }

            return sb.ToString();
        }
示例#28
0
 /// <summary>
 /// Renders a page to html string
 /// </summary>
 /// <param name="page">Page to render</param>
 /// <returns>Page as HTML string</returns>
 private static string RenderPage(Page page)
 {
     StringBuilder sb = new StringBuilder();
     StringWriter sw = new StringWriter(sb);
     Html32TextWriter hw = new Html32TextWriter(sw);
     StringWriter output = new StringWriter();
     HttpContext.Current.Server.Execute(page, hw, false);
     return sb.ToString();
 }
示例#29
0
        // Protected Methods
        //TODO remove this code block after test
        //this was the previous code, leaving here until after test
        protected void OldRender(Html32TextWriter writer)
        {
            if (this.RecordCount > 0)
            {
                writer.WriteLine(@"<div class=""Paging"">");
                if (this.PageNumber > 1)
                {
                    writer.WriteLine(@"<span class=""PagingPrevious""><a href=""{0}"">« Previous</a></span>",
                        this.BaseUrl + "/page/" + (this.PageNumber - 1));
                }

                writer.WriteLine(@"<span class=""PagingInfo"">Page {0} of {1}</span>",
                    this.PageNumber, this.PageCount);

                if (this.PageNumber < this.PageCount)
                {
                    writer.WriteLine(@"<span class=""PagingNext""><a href=""{0}"">Next »</a></span>",
                        this.BaseUrl + "/page/" + (this.PageNumber + 1));
                }

                writer.WriteLine(@"</div>");
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RewriteFormHtmlTextWriter"/> class.
 /// </summary>
 /// <param name="writer">The writer.</param>
 public RewriteFormHtmlTextWriter(Html32TextWriter writer)
     : base(writer)
 {
     this.InnerWriter = writer.InnerWriter;
 }
示例#31
0
        public static string Pager(this HtmlHelper htmlHelper, IPagination pagination, string actionName, string controllerName, RouteValueDictionary routeValues)
        {
            routeValues = routeValues ?? new RouteValueDictionary();
            var routeValueDictionary = new RouteValueDictionary(routeValues);
            if(!routeValueDictionary.ContainsKey("page"))
                routeValueDictionary.Add("page", 0);

            if(!routeValueDictionary.ContainsKey("controller"))
                routeValueDictionary.Add("controller", controllerName);

            int min = Math.Max(pagination.PageNumber - 2, 1);
            int max = Math.Min(pagination.PageNumber + 2, pagination.TotalPages);

            int startPage = Math.Min(min, 1);
            int endPage = Math.Max(max, pagination.TotalPages);
            int currentPage = pagination.PageNumber;

            var sb = new StringBuilder();
            var sw = new StringWriter(sb, System.Globalization.CultureInfo.InvariantCulture);
            var hw = new Html32TextWriter(sw, "    ");

            hw.WriteFullBeginTag("ul");

            if (pagination.HasPreviousPage)
            {
                hw.WriteLine();
                hw.WriteFullBeginTag("li");
                routeValueDictionary["page"] = currentPage - 1;
                hw.Write(htmlHelper.ActionLink("prev", actionName, routeValueDictionary,
                                               new Dictionary<string, object> {{"class", "previous"}}));
                hw.WriteEndTag("li");
            }

            if(min != startPage)
            {
                hw.WriteLine();
                hw.WriteFullBeginTag("li");
                routeValueDictionary["page"] = startPage;
                hw.Write(htmlHelper.ActionLink(startPage.ToInvariantString(), actionName, routeValueDictionary));
                hw.WriteEndTag("li");

                if (min - startPage > 1)
                {
                    hw.WriteFullBeginTag("li");
                    hw.Write("...");
                    hw.WriteEndTag("li");
                }
            }

            for (var i = min; i <= max; i++)
            {
                hw.WriteLine();
                hw.WriteFullBeginTag("li");
                routeValueDictionary["page"] = i;
                if (i == currentPage)
                {
                    hw.WriteFullBeginTag("span");
                    hw.Write(i.ToInvariantString());
                    hw.WriteEndTag("span");
                }
                else
                    hw.Write(htmlHelper.ActionLink(i.ToInvariantString(), actionName, routeValueDictionary));

                hw.WriteEndTag("li");
            }

            if(max != endPage)
            {
                if (endPage - max > 1)
                {
                    hw.WriteLine();
                    hw.WriteFullBeginTag("li");
                    hw.Write("...");
                    hw.WriteEndTag("li");
                }

                hw.WriteLine();
                hw.WriteFullBeginTag("li");
                routeValueDictionary["page"] = endPage;
                hw.Write(htmlHelper.ActionLink(endPage.ToInvariantString(), actionName, routeValueDictionary));
                hw.WriteEndTag("li");
            }

            if(pagination.HasNextPage)
            {
                hw.WriteLine();
                hw.WriteFullBeginTag("li");
                routeValueDictionary["page"] = currentPage + 1;
                hw.Write(htmlHelper.ActionLink("next", actionName, routeValueDictionary,
                                               new Dictionary<string, object> {{"class", "next"}}));
                hw.WriteEndTag("li");
            }

            hw.WriteLine();
            hw.WriteEndTag("ul");
            return sb.ToString();

            //StringBuilder sb1 = new StringBuilder();

            //int seed = pagination.PageNumber % pagination.PageSize == 0 ? pagination.PageNumber : pagination.PageNumber - (pagination.PageNumber % pagination.PageSize);

            //if (pagination.PageNumber > 1)
            //    sb1.AppendLine(htmlHelper.ActionLink("prev", "index", controllerName, new { page = pagination.PageNumber }));// String.Format("<a href=\"{0}/{1}\">Previous</a>", urlPrefix, pagination.PageNumber));

            //if (pagination.PageNumber - pagination.PageSize >= 1)
            //{
            //    var pageNumber = (pagination.PageNumber - pagination.PageSize) + 1)
            //    sb1.AppendLine(htmlHelper.ActionLink("...", "index", controllerName, new {page = pageNumber}));
            //}
            //for (int i = seed; i < Math.Round((pagination.TotalItems / 10) + 0.5) && i < seed + pagination.PageSize; i++)
            //{
            //    //sb1.AppendLine(htmlHelper.ActionLink("{0}".ToFormat(i + 1)) String.Format("<a href=\"{0}/{1}\">{1}</a>", urlPrefix, i + 1));
            //}

            //if (pagination.PageNumber + pagination.PageSize <= (Math.Round((pagination.TotalItems / 10) + 0.5) - 1))
            //    sb1.AppendLine(String.Format("<a href=\"{0}/{1}\">...</a>", urlPrefix, (pagination.PageNumber + pagination.PageSize) + 1));

            //if (currentPage < (Math.Round((pagination.TotalItems / 10) + 0.5) - 1))
            //    sb1.AppendLine(String.Format("<a href=\"{0}/{1}\">Next</a>", urlPrefix, pagination.PageNumber + 2));

            //return sb1.ToString();

            //var pagesToDisplay = 5;

            //var sb = new StringBuilder();
            //var textWriter = new StringWriter(sb);
            //var builder = new HtmlTextWriter(textWriter);

            ////opening ul tag
            //builder.RenderBeginTag("ul");

            ////prev tag
            //builder.RenderBeginTag("li");
            //if (pagination.HasPreviousPage)
            //    builder.Write(urlHelper.ActionLink("prev", actionName, new{id = pagination.PageNumber - 1}));
            //else
            //    builder.WriteEncodedUrl("prev");
            //builder.RenderEndTag();

            ////R
            //builder.RenderBeginTag("li");
            //if(pag)

            ////next tag
            //builder.RenderBeginTag("li");
            //if (pagination.HasPreviousPage)
            //    builder.Write(urlHelper.ActionLink("next", actionName, new { id = pagination.LastItem }));
            //else
            //    builder.WriteEncodedUrl("next");
            //builder.RenderEndTag();

            ////close ul tag
            //builder.RenderEndTag();
            //return sb.ToString();
        }