/// <summary> /// Convert a control settings into formatted string that is usable on the javascript. /// </summary> /// <returns>The javascript configuration string.</returns> private string GetConfigurationString() { StringBuilder configString = new StringBuilder(); string basePath = BasePath; if (basePath.StartsWith("~")) { basePath = ResolveUrl(basePath); } configString.AppendFormat("{0}={1}", "basepath", HttpUtility.UrlEncode(basePath)); configString.Append("&"); configString.AppendFormat("{0}={1}", "doctype", HttpUtility.UrlEncode(DocumentType)); configString.Append("&"); configString.AppendFormat("{0}={1}", "textformat", TextFormat); configString.Append("&"); string imagePath = ImagePath.StartsWith("~") ? ResolveUrl(ImagePath) : ImagePath; configString.AppendFormat("{0}={1}", "imagepath", imagePath); configString.Append("&"); if (string.IsNullOrEmpty(EditorImagePath) == false) { string toolbarImages = EditorImagePath.StartsWith("~") ? ResolveUrl(EditorImagePath) : EditorImagePath; configString.AppendFormat("{0}={1}", "editorimagepath", toolbarImages); configString.Append("&"); } if (string.IsNullOrEmpty(EditorCss) == false) { string editorCSS = EditorCss.StartsWith("~") ? ResolveUrl(EditorCss) : EditorCss; configString.AppendFormat("{0}={1}", "editorcss", editorCSS); configString.Append("&"); } configString.AppendFormat("{0}={1}", "mode", Mode.ToString("D")); configString.Append("&"); configString.AppendFormat("{0}={1}", "usebroncr", UserBRonCarriageReturn); configString.Append("&"); configString.Append("fontsize="); int i = 1; foreach (FontUnit u in TypeDescriptor.GetConverter(ControlStyle.Font.Size).GetStandardValues()) { if (3 < i) { configString.AppendFormat("{0}*{1},", i - 3, u); } i++; } configString.Remove(configString.Length - 1, 1); configString.Append("&fonts="); if (0 != ControlStyle.Font.Names.Length) { for (i = 0; i < ControlStyle.Font.Names.Length; i++) { configString.AppendFormat("{0};", ControlStyle.Font.Names[i]); } configString.Remove(configString.Length - 1, 1); } else { // default font configString.Append("Arial;Times New Roman;Verdana;Tahoma"); } return(configString.ToString()); }
/// <summary> /// Render this control to the output parameter specified. /// </summary> /// <param name="output"> The HTML writer to write out to </param> protected override void Render(HtmlTextWriter output) { // control is already rendered if (isRendered) { return; } output.Write("<div>"); if (CheckBrowserCompatibility()) { string basePath = "~/HtmlEditor.aspx"; if (basePath.StartsWith("~")) { basePath = ResolveUrl(basePath); } //if (!File.Exists(MapPathSecure(basePath))) //{ // // Directory not found throw BasePath Exception // throw new BasePathException(basePath); //} basePath += string.Format("?res=editor&id={0}", ClientID); if (string.IsNullOrEmpty(EditorCss) == false) { string editorCSS = EditorCss.StartsWith("~") ? ResolveUrl(EditorCss) : EditorCss; basePath += string.Format("&cssFile={0}", editorCSS); } //basePath += "editor.htm?ClientId=" + ClientID; // make hidden field that store configuration settings output.Write("<input type=\"hidden\" id=\"{0}__CONFIG\" name=\"{1}__CONFIG\" value=\"{2}\" />", ClientID, ClientID, GetConfigurationString()); //Stupid work-around for CallBack events. It fixes the Anthem.Net have 'BADRESPONSE' if (!string.IsNullOrEmpty(Text)) { Text = Text.Replace("\"", "'"); } // make hidden filed that referenced to the edited document output.Write("<input type=\"hidden\" id=\"{0}\" name=\"{1}\" value=\"{2}\" />", ClientID, ClientID, HttpUtility.HtmlEncode(Text)); // make editor's IFRAME. // output.Write("<iframe id=\"{0}__Frame\" src=\"{1}\" widthEditableArea=\"{2}\" heightEditableContent=\"{3}\" frameborder=\"no\" scrolling=\"no\"></iframe>", // ClientID, basePath, WidthEditableColumn, HeightEditableColumn); output.Write( "<iframe id=\"{0}__Frame\" src=\"{1}\" width=\"{2}\" height=\"{3}\" frameborder=\"no\" scrolling=\"no\"></iframe>", ClientID, basePath, Width, Height); } else { output.Write( "<textarea name=\"{0}\" rows=\"4\" cols=\"40\" style=\"width: {1}; height: {2}\" >{3}</textarea>", ClientID, Width, Height, HttpUtility.HtmlEncode(Text)); } output.Write("</div>"); }