public void RenderToStream(Stream stream) { using (StreamWriter streamWriter = new StreamWriter(stream)) { using (HtmlTextWriter writer = new HtmlTextWriter(streamWriter)) { _container.RenderControl(writer); } } }
protected override void Render(HtmlTextWriter writer) { if (this.RenderName) { controlToRender.Attributes.Add("class", this.CssClass); HtmlGenericControl div = new HtmlGenericControl(); div.TagName = "div"; div.Style.Add("display", "inline-block"); div.Attributes.Add("class", this.NameCssClass); div.Controls.Add(new LiteralControl(Name)); div.RenderControl(writer); } if (this.CanEdit) { base.Render(writer); } else { this.InputElementTagName = "input"; JsonHiddenInput hiddenInput = new JsonHiddenInput(); hiddenInput.JsonId = this.JsonId; hiddenInput.Value = this.Value; hiddenInput.RenderControl(writer); this.controlToRender.Controls.Clear(); this.controlToRender.TagName = "span"; this.controlToRender.Attributes.Add("class", this.CssClass); this.controlToRender.Controls.Add(new LiteralControl(this.Text)); this.controlToRender.RenderControl(writer); } }
public void ExportToExcel(GridView gvPDFTemp, string fileName) { gvPDFTemp.Style.Add("font-size", "8px"); gvPDFTemp.HeaderStyle.BackColor = System.Drawing.Color.Yellow; // gvPDFTemp.DataBind(); HtmlGenericControl divTop = new HtmlGenericControl("div"); StringWriter sw1 = new StringWriter(); HtmlTextWriter hw1 = new HtmlTextWriter(sw1); gvPDFTemp.RenderControl(hw1); StringReader sr1 = new StringReader(sw1.ToString()); string html = GetHeaderText(sr1, fileName); divTop.InnerHtml = html; HttpContext context = HttpContext.Current; context.Response.ClearContent(); // context.Response.ContentType = "application/ms-excel"; context.Response.ContentType = "text/vnd.ms-excel"; context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName + ".xls"); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); // gvPDFTemp.RenderControl(hw); divTop.RenderControl(hw); HttpContext.Current.Response.Write(sw); HttpContext.Current.Response.End(); }
/// <summary> /// Renders the base control. /// </summary> /// <param name="writer">The writer.</param> public void RenderBaseControl(HtmlTextWriter writer) { writer.AddAttribute("class", "controls"); writer.RenderBeginTag(HtmlTextWriterTag.Div); string selectedText = SelectedItem != null ? SelectedItem.Text : Title; _btnSelect.Controls.Clear(); _btnSelect.Controls.Add(new LiteralControl { Text = string.Format("{0} <span class='fa fa-caret-down'></span>", selectedText) }); foreach (var item in this.Items.OfType <ListItem>()) { string controlHtmlFormat = "<li><a href='#' data-id='{0}'>{1}</a></li>"; _listControl.Controls.Add(new LiteralControl { Text = string.Format(controlHtmlFormat, item.Value, item.Text) }); } _divControl.RenderControl(writer); _hfSelectedItemId.RenderControl(writer); _hfSelectedItemText.RenderControl(writer); writer.RenderEndTag(); }
private void RenderHead() { var head = new HtmlGenericControl("head"); head.Controls.Add(new HtmlMeta { HttpEquiv = "content-Type", Content = "text/html; charset=utf8" }); head.Controls.Add(new HtmlMeta { HttpEquiv = "Date", Content = DateTime.Now.ToString() }); var title = new HtmlTitle(); if (SchemaName == null) { title.Controls.AddLiteral("Scripts - DBCompare"); } else { title.Controls.AddLiteral("[{0}].[{1}] Scirpt - DBCompare", SchemaName, TableName); } head.Controls.Add(title); var link = new HtmlLink(); link.Attributes["rel"] = "Stylesheet"; link.Attributes["type"] = "text/css"; link.Href = WebService.GetFileUrl("DBCompare.css"); head.Controls.Add(link); head.RenderControl(HWriter); }
public HttpResponseMessage GetMarkerEditForm(string filename, bool richtext = false) { string result = Common.GetResourceText(filename); StringBuilder sbFiles = new StringBuilder(); string folderPath = "/Umbraco/Images/MapPins/"; if (Directory.Exists(HttpContext.Current.Server.MapPath(folderPath))) { foreach (string file in Directory.GetFiles(HttpContext.Current.Server.MapPath(folderPath))) { using (StringWriter stringWriter = new StringWriter()) { using (HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter)) { HtmlGenericControl optionHtml = new HtmlGenericControl("option"); optionHtml.Attributes.Add("value", string.Concat(folderPath, Path.GetFileName(file))); optionHtml.InnerText = Path.GetFileName(file); optionHtml.RenderControl(htmlWriter); sbFiles.Append(stringWriter.ToString()); optionHtml.Dispose(); } } } } return(new HttpResponseMessage() { Content = new StringContent(string.Format(result, sbFiles.ToString(), richtext ? "richtext-fix" : string.Empty), System.Text.Encoding.UTF8, "application/html") }); }
public void ASPXToPDF(HtmlGenericControl objhtml) { string fileName = "AsignacionFolios.pdf"; HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.Clear(); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); objhtml.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A2, 5f, 5f, 5f, 5f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, HttpContext.Current.Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); HttpContext.Current.Response.ContentType = "application/pdf"; HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + fileName); HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); HttpContext.Current.Response.Write(pdfDoc); HttpContext.Current.Response.End(); }
//<label class="custom-control custom-checkbox"> // <input id = "chkRememberMe" runat="server" type="checkbox" class="custom-control-input"> // <span class="custom-control-indicator"></span> // <span class="custom-control-description">Ricordami</span> //</label> private void renderCheckBox(HtmlTextWriter writer, string id, string text) { HtmlGenericControl label = new HtmlGenericControl("label"); label.Attributes.Add("class", "custom-control custom-checkbox"); HtmlGenericControl input = new HtmlGenericControl("input"); input.Attributes.Add("type", "checkbox"); input.Attributes.Add("class", "custom-control-input"); input.ID = id; HtmlGenericControl span = new HtmlGenericControl("span"); span.Attributes.Add("class", "custom-control-indicator"); HtmlGenericControl span2 = new HtmlGenericControl("span"); span2.Attributes.Add("class", "custom-control-description"); span2.InnerText = text; label.Controls.Add(input); label.Controls.Add(span); label.Controls.Add(span2); label.RenderControl(writer); }
protected override void Render(HtmlTextWriter writer) { if (this.Items == null || this.Items.Count == 0) { return; } switch (Type) { case uiType.CheckBox: foreach (ListItem i in this.Items) { renderCheckBox(writer, i.Value, i.Text); } break; case uiType.RadioButton: HtmlGenericControl div = new HtmlGenericControl("div"); div.Attributes.Add("class", "custom-controls-stacked"); foreach (ListItem i in this.Items) { div.Controls.Add(renderRadioButton(i.Value, i.Text)); } div.RenderControl(writer); break; } }
public override string XGetDesignTimeHtml(DesignerRegionCollection regions) { if (regions == null) { base.GetDesignTimeHtml(regions); } this.designerRegions = regions; HtmlGenericControl tabPanel = new HtmlGenericControl("div"); tabPanel.Attributes["class"] = "{0}{1}".FormatWith(this.tabPanelControl.BaseCls, !this.tabPanelControl.Border ? " x-tab-panel-noborder" : ""); tabPanel.Style["width"] = this.tabPanelControl.Width == Unit.Empty ? "auto" : this.tabPanelControl.Width.ToString(); if (this.tabPanelControl.TabPosition == TabPosition.Top && this.tabPanelControl.Items.Count > 0) { tabPanel.Controls.Add(BuildTabs(TabPosition.Top)); } tabPanel.Controls.Add(this.BuildBody()); StringWriter sr = new StringWriter(CultureInfo.CurrentCulture); HtmlTextWriter hw = new HtmlTextWriter(sr); tabPanel.RenderControl(hw); return(sr.ToString()); }
protected override void RenderContents(System.Web.UI.HtmlTextWriter writer) { var propertiesLabel = new HtmlGenericControl("span"); //populate the value of the label control with the properties of your custom control if (base.State == SourceCode.Forms.Controls.Web.Shared.ControlState.Designtime || base.State == SourceCode.Forms.Controls.Web.Shared.ControlState.Preview ) { propertiesLabel.ID = this.ID + "_propertiesLabel"; propertiesLabel.InnerText = "(" + this.GetType().FullName + " - Design Time)"; } if (base.State == SourceCode.Forms.Controls.Web.Shared.ControlState.Runtime) { propertiesLabel.ID = this.ID + "_propertiesLabel"; if (OutputDebugInfo) { propertiesLabel.InnerText = "(" + this.GetType().FullName + " - Runtime) " + System.Environment.NewLine + "Control Text: " + this.Text + System.Environment.NewLine + "Control Value: " + this.Value + System.Environment.NewLine + "Control Id: " + this.ID + System.Environment.NewLine + "Enabled: " + this.IsEnabled + System.Environment.NewLine + "Visible: " + this.IsVisible; } else { propertiesLabel.InnerText = this.Text; } } propertiesLabel.RenderControl(writer); }
public static void ToExcel(HtmlGenericControl gv, string strFileName) { if (strFileName.ToLower().IndexOf(".xls") <= 0) { strFileName += ".xls"; } try { StringWriter tw; tw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(tw); gv.RenderControl(hw); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.Charset = "UTF8"; HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;//×¢Òâ±àÂë HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName, Encoding.UTF8).ToString()); HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; HttpContext.Current.Response.Write(tw.ToString()); HttpContext.Current.Response.End(); } catch (Exception ex) { HttpContext.Current.Response.End(); HttpContext.Current.Response.Write("<script>alert('" + ex.Message + "')</script>"); } }
/// <summary>Renders the open popup button.</summary> private void RenderButton(HtmlTextWriter writer) { HtmlGenericControl span = new HtmlGenericControl("span"); Controls.Add(span); HtmlInputButton cb = new HtmlInputButton(); span.Controls.Add(cb); HtmlInputButton pb = new HtmlInputButton(); span.Controls.Add(pb); span.Attributes["class"] = "selectorButtons"; pb.Value = ButtonText; pb.Attributes["title"] = Utility.GetGlobalResourceString("UrlSelector", "Select") ?? "Select"; pb.Attributes["class"] = "popupButton selectorButton"; pb.Attributes["onclick"] = string.Format(OpenPopupFormat, N2.Web.Url.ResolveTokens(BrowserUrl), ClientID, PopupOptions, DefaultMode, AvailableModes, SelectableTypes, SelectableExtensions ); cb.Value = "x"; cb.Attributes["title"] = Utility.GetGlobalResourceString("UrlSelector", "Clear") ?? "Clear"; cb.Attributes["class"] = "clearButton"; cb.Attributes["onclick"] = "document.getElementById('" + ClientID + "').value = '';"; span.RenderControl(writer); }
/// <summary> /// Renders the base control. /// </summary> /// <param name="writer">The writer.</param> public void RenderBaseControl(HtmlTextWriter writer) { writer.AddAttribute("class", "controls"); writer.RenderBeginTag(HtmlTextWriterTag.Div); string selectedText = ((this.SelectionStyle == ButtonSelectionStyle.Title) && SelectedItem != null) ? SelectedItem.Text : Title; _btnSelect.Controls.Clear(); _btnSelect.Controls.Add(new LiteralControl { Text = string.Format("{0} <span class='fa fa-caret-down'></span>", selectedText) }); foreach (var item in this.Items.OfType <ListItem>()) { string faChecked = (this.SelectionStyle == ButtonSelectionStyle.Checkmark) && (SelectedValue == item.Value) ? "fa-check" : string.Empty; string html = string.Format( "<li><a href='#' data-id='{0}'><i class='js-selectionicon fa fa-fw {2}'></i> {1}</a></li>", item.Value, item.Text, faChecked); _listControl.Controls.Add(new LiteralControl { Text = html }); } _divControl.RenderControl(writer); _hfSelectedItemId.RenderControl(writer); writer.RenderEndTag(); }
private void RenderHead() { var head = new HtmlGenericControl("head"); head.Controls.Add(new HtmlMeta { HttpEquiv = "content-Type", Content = "text/html; charset=utf8" }); head.Controls.Add(new HtmlMeta { HttpEquiv = "Date", Content = DateTime.Now.ToString() }); var title = new HtmlTitle(); title.Controls.AddLiteral("[{0}].[{1}] Comparison Details - DBCompare", SchemaName, TableName); head.Controls.Add(title); head.Controls.Add(CreateStylesheetElement("jquery-ui-1.10.3.custom.min.css")); head.Controls.Add(CreateStylesheetElement("DBCompare.css")); head.Controls.Add(CreateScriptElement("jquery-1.10.1.min.js")); head.Controls.Add(CreateScriptElement("jquery-ui-1.10.3.custom.min.js")); head.Controls.Add(CreateScriptElement("DBCompare.js")); head.RenderControl(HWriter); }
string RenderHTML() { if (_Cache.ContainsKey(_LetterType)) { return(_Cache[_LetterType]); } else { HtmlGenericControl ul = BindLetterList(); StringWriter sw = new StringWriter(); ul.RenderControl(new HtmlTextWriter(sw)); string s = sw.ToString(); if (!_Cache.ContainsKey(_LetterType)) { lock (_lock) { if (!_Cache.ContainsKey(_LetterType)) { _Cache.Add(_LetterType, s); } } } return(s); } }
protected override void Render(System.Web.UI.HtmlTextWriter writer) { if (!DesignMode) { if (Page.Items["__BrowseFile"] == null) { String iframeid = "_" + this.ClientID; Page.Items["__BrowseFile"] = iframeid; //HtmlGenericControl iframe = new HtmlGenericControl("script"); //iframe.Attributes["type"] = "text/javascript"; //iframe.Attributes["src"] = Page.ClientScript.GetWebResourceUrl(GetType(), "WebSite.Controls.WebControls.BrowseFile.CkFinder.js"); HtmlGenericControl iframe = new HtmlGenericControl("iframe"); iframe.Attributes["src"] = Page.ClientScript.GetWebResourceUrl(GetType(), "WebSite.Controls.WebControls.BrowseFile.CkFinder.html"); iframe.Attributes["id"] = iframeid; iframe.Attributes["name"] = iframeid; iframe.Attributes["style"] = "display:none;"; iframe.Attributes["frameborder"] = "0"; iframe.RenderControl(writer); } } //this.ReadOnly = true; base.Render(writer); writer.Write(String.Format("<a style=\"padding-left:5px\" href=\"javascript:\" onclick=\"window.frames['{4}'].BrowseFile({{ResourceType:'{0}',ClientID:'{1}',Multiple:{2},Folder:'{0}:/{3}/'}});\">", this.ResourceType, this.ClientID, this.SelectMultiple.ToString().ToLower(), DateTime.Now.ToString("yyyy-MM-dd"), Page.Items["__BrowseFile"])); writer.Write("浏览"); writer.Write("</a>"); }
/// <summary> /// 导出到excel /// </summary> /// <param name="p">网页的实体</param> /// <param name="ctr">需要导出的内容</param> public static bool expExcle(Page p, HtmlGenericControl ctr) { bool b = false; if (!LyfHelper.lyf.IsPass()) { return(b); } p.Response.Clear();//清除缓冲区流中的所有内容输出 //name:要添加 value 的 HTTP 头名称。 //value:要添加到头中的字符串。 //p.Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); p.Response.AddHeader("content-disposition", "inline;filename=FileName.xls"); //中文正常 //p.Response.Charset = "utf-8";//获取或设置输出流的 HTTP 字符集 p.Response.ContentEncoding = System.Text.Encoding.UTF8;//获取或设置输出流的 HTTP 字符集 //中文为乱码 //p.Response.Charset = "GB2312";//获取或设置输出流的 HTTP 字符集 //p.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//获取或设置输出流的 HTTP 字符集 p.Response.ContentType = "application/ms-excel";// 输出流的 HTTP MIME 类型。默认值为“text/html” StringWriter stringWrite = new StringWriter(); HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); ctr.RenderControl(htmlWrite); p.Response.Write(stringWrite.ToString()); p.Response.End(); b = true; return(b); }
/// <summary> /// Override render to control the exact output of what is rendered this includes instantiating the jquery plugin /// </summary> /// <param name="writer">The <see cref="T:System.Web.UI.HtmlTextWriter"/> object that receives the server control content.</param> /// <remarks> /// Generally i don't like to do this but there's a few div's, etc... to render so this makes more sense. /// </remarks> protected override void Render(HtmlTextWriter writer) { //<div class="multiTreePicker"> // <div class="header propertypane"> // <div>Select items</div> // </div> // <div class="left propertypane"> // <umb:tree runat="server" ID="TreePickerControl" // CssClass="myTreePicker" Mode="Standard" // DialogMode="id" ShowContextMenu="false" // IsDialog="true" TreeType="content" /> // </div> // <div class="right propertypane"> // </div> //</div> RenderTooltip(writer); writer.AddAttribute("class", (!MinItemsValidator.IsValid ? "error " : "") + "multiNodePicker clearfix"); writer.AddAttribute("id", this.ClientID); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddAttribute("class", "header propertypane"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.Write("Select Items"); writer.RenderEndTag(); writer.RenderEndTag(); writer.AddAttribute("class", "left propertypane"); writer.AddStyleAttribute(HtmlTextWriterStyle.Height, ((ControlHeight + 10).ToString() + "px")); writer.RenderBeginTag(HtmlTextWriterTag.Div); //add the tree control here TreePickerControl.RenderControl(writer); writer.RenderEndTag(); RightColumn.RenderControl(writer); //render the hidden field PickedValue.RenderControl(writer); writer.RenderEndTag(); //end multiNodePicker div var tooltipAjaxUrl = IOHelper.ResolveUrl(SystemDirectories.Umbraco) + @"/controls/Tree/CustomTreeService.asmx/GetNodeInfo"; //add jquery window load event to create the js tree picker var jsMethod = string.Format("jQuery('#{0}').MultiNodeTreePicker('{1}', {2}, '{3}', {4}, {5}, '{6}', '{7}');", TreePickerControl.ClientID, this.ClientID, MaxNodeCount, tooltipAjaxUrl, ShowToolTips.ToString().ToLower(), (TreeToRender == Umbraco.Core.Constants.Applications.Media && ShowThumbnailsForMedia).ToString().ToLower(), IOHelper.ResolveUrl(SystemDirectories.Umbraco), TreeToRender); var js = "jQuery(window).load(function() { " + jsMethod + " });"; writer.WriteLine("<script type='text/javascript'>" + js + "</script>"); }
public override void RenderControl(HtmlTextWriter writer) { if (this.Visible) { this.EnsureBreadcrumbs(); m_Container.RenderControl(writer); } }
public void RenderDocument(HttpContext context, HtmlGenericControl documentRoot) { context.Response.Write("<!DOCTYPE html>"); documentRoot.RenderControl(new XhtmlTextWriter(context.Response.Output)); return; }
protected override void RenderContents(HtmlTextWriter output) { HtmlGenericControl ctrl = new HtmlGenericControl("PRE"); ctrl.Attributes["class"] = CssClass; ctrl.InnerText = Text; ctrl.RenderControl(output); }
protected override void RenderContents(System.Web.UI.HtmlTextWriter writer) { base.RenderContents(writer); if (base.State == SourceCode.Forms.Controls.Web.Shared.ControlState.Runtime) { var divWrapper = new HtmlGenericControl("div"); divWrapper.Attributes.Add("class", "signaturepad-wrapper"); divWrapper.ID = this.ID + "_wrapper"; var canvas = new HtmlGenericControl("canvas"); canvas.Attributes.Add("class", "signaturepad-canvas"); canvas.ID = this.ID + "_canvas"; divWrapper.Controls.Add(canvas); divWrapper.RenderControl(writer); // //sig pad // //<div class='sigPad'> // var divSigPad = new HtmlGenericControl("div"); // divSigPad.Attributes.Add("class", "sigPad"); //// <div class='sig sigWrapper'> // var divTagWrapper = new HtmlGenericControl("div"); // divTagWrapper.Attributes.Add("class", "sig sigWrapper"); // // <canvas class='pad' // HtmlGenericControl canvasTag = new HtmlGenericControl("canvas"); // canvasTag.Attributes.Add("class", "pad"); // divTagWrapper.Controls.Add(canvasTag); // divSigPad.Controls.Add(divTagWrapper); // //sig img // // <div class='sigImg' // HtmlGenericControl divTagImg = new HtmlGenericControl("div"); // divTagImg.Attributes.Add("class", "sigImg"); // divTagImg.Style.Add(HtmlTextWriterStyle.Display, "none"); // divSigPadWrapper.Controls.Add(divSigPad); // divSigPadWrapper.Controls.Add(divTagImg); } else { var icon = new Image(); var page = this.Page; if (page == null) { page = new System.Web.UI.Page(); } icon.ImageUrl = page.ClientScript.GetWebResourceUrl(this.GetType(), string.Format("K2NE.Controls.SignaturePad.Resources.placeholder.png")); icon.Width = new Unit("100%"); icon.Height = new Unit("100%"); icon.RenderControl(writer); } }
private static MvcHtmlString GoogleMap(HtmlHelper helper, string id, Models.Map map, bool editor) { StringBuilder sbControlHtml = new StringBuilder(); using (StringWriter stringWriter = new StringWriter()) { using (HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter)) { //Generate container div control HtmlGenericControl divWrapperControl = new HtmlGenericControl("div"); HtmlGenericControl divMapControl = new HtmlGenericControl("div"); divMapControl.Attributes.Add("class", "map-container"); divMapControl.Attributes.Add("id", string.Format("map-{0}", id)); if (map.height > 0 || map.width > 0) { string widthStyle = "width:{0}px;"; if (map.width > 0) { widthStyle = string.Format(widthStyle, map.width); } else { widthStyle = string.Empty; } string heightStyle = "height:{0}px;"; if (map.height > 0) { heightStyle = string.Format(heightStyle, map.height); } else { heightStyle = string.Empty; } divMapControl.Attributes.Add("style", string.Concat(widthStyle, heightStyle)); } divWrapperControl.Controls.Add(divMapControl); //value input control HtmlInputHidden hidden = new HtmlInputHidden(); HtmlInputHidden hiddenValueControl = new HtmlInputHidden(); hiddenValueControl.ID = id; divWrapperControl.Controls.Add(hiddenValueControl); HtmlGenericControl scriptControl = new HtmlGenericControl("script"); scriptControl.Attributes.Add("type", "text/javascript"); scriptControl.InnerHtml = string.Format(@"$(document).ready(function(){{ $('#map-{0}').GoogleMapEditor($.extend({{}},{1},{{dataChange:function(sender, data){{ $(sender.container).next().next().val(data); }}}}));}});", id, map.ToJsonString()); divWrapperControl.Controls.Add(scriptControl); divWrapperControl.RenderControl(htmlWriter); sbControlHtml.Append(stringWriter.ToString()); divWrapperControl.Dispose(); } } return(new MvcHtmlString(sbControlHtml.ToString())); }
/// <summary> /// 用指定的信息呈现列表中的项 /// </summary> /// <param name="itemType"><see cref="ListItemType"/> 枚举值之一</param> /// <param name="repeatIndex">指定列表控件中项的位置的序号索引。</param> /// <param name="repeatInfo">表示用于呈现列表中的项的信息。</param> /// <param name="writer">表示要在客户端呈现 HTML 内容的输出流。</param> protected virtual void RenderItem(ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer) { ListItem item = this.Items[repeatIndex]; Literal checktext = new Literal(); checktext.Text = item.Selected ? this.CheckedText : this.UnCheckedText; HtmlGenericControl controlToRepeat = new HtmlGenericControl("span"); controlToRepeat.Attributes.Clear(); if (item.Attributes.Count > 0) { foreach (string str in item.Attributes.Keys) { controlToRepeat.Attributes[str] = item.Attributes[str]; } } controlToRepeat.ID = repeatIndex.ToString(NumberFormatInfo.InvariantInfo); controlToRepeat.InnerText = item.Text; if (repeatIndex != 0) { Literal splittext = new Literal(); splittext.Text = this.SplitString; splittext.RenderControl(writer); } switch (this.TextAlign) { default: { checktext.RenderControl(writer); controlToRepeat.RenderControl(writer); } break; case TextAlign.Left: { controlToRepeat.RenderControl(writer); checktext.RenderControl(writer); } break; } }
private string RenderMonths() { SortedDictionary <DateTime, int> months = GetPostsPerMonth(); if (months.Keys.Count == 0) { return("<p>" + Resources.labels.none + "</p>"); } HtmlGenericControl ul = new HtmlGenericControl("ul"); ul.Attributes.Add("id", "monthList"); HtmlGenericControl year = null; HtmlGenericControl list = null; int current = 0; foreach (DateTime date in months.Keys) { if (current == 0) { current = date.Year; } if (date.Year > current || ul.Controls.Count == 0) { list = new HtmlGenericControl("ul"); list.ID = "year" + date.Year.ToString(); year = new HtmlGenericControl("li"); year.Attributes.Add("class", "year"); year.Attributes.Add("onclick", "BlogEngine.toggleMonth('year" + date.Year + "')"); year.InnerHtml = date.Year.ToString(); year.Controls.Add(list); if (date.Year == DateTime.Now.Year) { list.Attributes.Add("class", "open"); } ul.Controls.AddAt(0, year); } HtmlGenericControl li = new HtmlGenericControl("li"); HtmlAnchor anc = new HtmlAnchor(); anc.HRef = Utils.RelativeWebRoot + date.Year + "/" + date.ToString("MM") + "/default" + BlogSettings.Instance.FileExtension; anc.InnerHtml = DateTime.Parse(date.Year + "-" + date.Month + "-01").ToString("MMMM") + " (" + months[date] + ")"; li.Controls.Add(anc); list.Controls.AddAt(0, li); current = date.Year; } System.IO.StringWriter sw = new System.IO.StringWriter(); ul.RenderControl(new HtmlTextWriter(sw)); return(sw.ToString()); }
private string GenerateMenu() { string result = null; try { var menus = GetMenus(); if (menus != null) { var listParent = menus.Where(m => m.ParentID == "").ToList(); var ul = new HtmlGenericControl("ul"); ul.Attributes["class"] = @"menu"; ul.ID = "menu1"; foreach (var item in listParent) { var li = new HtmlGenericControl("li"); var listChildren = GetChildrenMenu(item.ID, menus); if (listChildren != null && listChildren.Count() > 0) { var a = new HtmlGenericControl("a"); a.Attributes["href"] = "#"; a.InnerHtml = item.Name; li.Controls.Add(a); ul.Controls.Add(li); li.Controls.Add(AddChildrenMenu(item.ID, menus, li)); } else { var a = new HtmlGenericControl("a"); if (string.IsNullOrEmpty(item.Controller)) { a.Attributes["href"] = "#"; } else { a.Attributes["href"] = "/" + item.Controller + (string.IsNullOrEmpty(item.Action) ? "" : "/" + item.Action) + (string.IsNullOrEmpty(item.Param) ? "" : ("/?" + item.Param)); } a.InnerHtml = item.Name; li.Controls.Add(a); ul.Controls.Add(li); } } using (System.IO.StringWriter swriter = new System.IO.StringWriter()) { HtmlTextWriter writer = new HtmlTextWriter(swriter); ul.RenderControl(writer); result = swriter.ToString(); } } } catch (Exception ex) { LogHelper.Error("Controller: " + Request.RequestContext.RouteData.Values["Controller"].ToString() + " Action: " + Request.RequestContext.RouteData.Values["Action"].ToString() + " Method GenerateMenu:" + ex.Message + " Inner Exception: " + ex.InnerException.Message); return(null); } return(result); }
public static string GetHtml(HtmlGenericControl control) { StringBuilder s = new StringBuilder(); HtmlTextWriter tw = new HtmlTextWriter(new StringWriter(s)); control.RenderControl(tw); tw.Flush(); return(s.ToString()); }
/// <summary> /// Renders control. /// </summary> /// <param name="writer">The HtmlTextWriter to render content to.</param> protected override void Render(HtmlTextWriter writer) { if (writer == null) { return; } bool renderSecondRow = ((Required || (RangeValidation && ValidationType != CustomValidationDataType.String) || RegularExpressionValidation) && Enabled && (!ReadOnly)); if (this.Theme != MasterPageTheme.Modern) { BaseValidatedControl.RenderValidatedControlBeginTag(Required && ShowRequired, writer, this.Width); } if (Masked) { if (!this.Width.IsEmpty) { m_RadMaskedTextBox.Width = ((this.Theme == MasterPageTheme.Modern) ? this.Width : Unit.Percentage(100)); } m_RadMaskedTextBox.RenderControl(writer); } else { if (!this.Width.IsEmpty) { m_TextBox.Width = ((this.Theme == MasterPageTheme.Modern) ? this.Width : Unit.Percentage(100)); } if (MultiLineMode && (MaxLength > 0)) { m_TextBox.Attributes.Add("maxLength", MaxLength.ToString(CultureInfo.CurrentCulture)); } m_TextBox.RenderControl(writer); if (LengthInfoEnabled) { string lengthInfoStringFormat = ((MaxLength > 0) ? Resources.TextBox_LengthInfoStringFormat2 : Resources.TextBox_LengthInfoStringFormat1); writer.Write("<br />"); m_Span.RenderControl(writer); writer.Write(string.Format(CultureInfo.CurrentCulture, " " + lengthInfoStringFormat, MaxLength)); } } if (this.Theme != MasterPageTheme.Modern) { BaseValidatedControl.RenderValidatedControlMiddleTag(renderSecondRow, writer); } this.RenderValidators(writer); if (this.Theme != MasterPageTheme.Modern) { BaseValidatedControl.RenderValidatedControlEndTag(renderSecondRow, writer); } }
/// <summary> /// Renders out input field with honeypot security check enabled /// </summary> /// <param name="helper">HtmlHelper which will be extended</param> /// <param name="name">Name of field. Should match model field of string type</param> /// <param name="value">Value of the field</param> /// <param name="addLabel">true if the the input has a label. Default: true</param> /// <param name="labelContent">Label content. Default : name param</param> /// <param name="inputCss">CSS class to be applied to the visible input field. Default: null</param> /// <param name="fieldType">Enum represents the visible input type.Default: InputType.Text</param> /// <param name="honeypotCss">CSS class to be applied to the trap input field</param> /// <param name="honeypotType">Enum represents the input type. Default: InputType.Hidden</param> /// <returns>Returns render out MvcHtmlString for displaying on the View</returns> public static MvcHtmlString HoneyPotField(this HtmlHelper helper, string name, object value, bool addLabel = true, string labelContent = null, string inputCss = null, InputType fieldType = InputType.Text, string honeypotCss = null, InputType honeypotType = InputType.Hidden) { if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } StringBuilder sbControlHtml = new StringBuilder(); using (StringWriter stringWriter = new StringWriter()) { using (HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter)) { HtmlInputText hashedField = new HtmlInputText(fieldType.ToString().ToLower()); string hashedName = GetHashedPropertyName(name); hashedField.Value = value != null?value.ToString() : String.Empty; hashedField.ID = hashedName; hashedField.Name = hashedName; if (!String.IsNullOrWhiteSpace(inputCss)) { hashedField.Attributes["class"] = inputCss; } if (addLabel) { HtmlGenericControl label = new HtmlGenericControl("label"); if (String.IsNullOrEmpty(labelContent)) { label.InnerText = name; } else { label.InnerText = labelContent; } label.Attributes.Add("for", hashedName); label.Attributes.Add("style", "margin-right: 15px"); label.RenderControl(htmlWriter); } hashedField.RenderControl(htmlWriter); HtmlInputText hiddenField = new HtmlInputText(honeypotType.ToString().ToLower()); hiddenField.Value = String.Empty; hiddenField.ID = name; hiddenField.Name = name; if (!String.IsNullOrWhiteSpace(honeypotCss)) { hiddenField.Attributes["class"] = honeypotCss; } hiddenField.RenderControl(htmlWriter); sbControlHtml.Append(stringWriter.ToString()); } } return(new MvcHtmlString(sbControlHtml.ToString())); }
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()); }