导航

【ASP.NET】FreeTextBox的使用方法

Posted on 2007-11-05 22:20  xujh  阅读(116)  评论(0编辑  收藏  举报
 到www.freetextbox.com网站上,里面有个 Download Control (3.1.6) (zip)
  • 点击就可以了,下完以后是个压缩文件,解压开来,有这几个主要文件:

    aspnet_client          FreeTextBox的外观文件,直接拷贝到你的工程的目录下就可以了。

    Docs                        文档嘛,就是说明文档,只有一个帮助文件

    examples              这是人家官方调试好的例子

    Framework-2.0     适合.net freameork2.0使用的dll(命名空间)

    Framework-1.1     适合.net freameork1.1使用的dll(命名空间)

    Framework-1.0     适合.net freameork1.0使用的dll(命名空间)

     只要把Framework-2.0/Framework-1.1/Framework-1.0三个中适合你用的那个dll拷贝到你工程下的bin目录下,将

    aspnet_client 拷贝到工程目录下,然后你可以随便的调试任何一个例子都很容易通过的。 

    这是一个例子:

    Default.aspx

     

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" ValidateRequest="false"%>
    <%@ Register TagPrefix="FTB" Namespace="FreeTextBoxControls" Assembly="FreeTextBox" %>
    <%@ Register TagPrefix="FCKeditorV2" Namespace="FredCK.FCKeditorV2" Assembly="FredCK.FCKeditorV2" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">

    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        
    <title>无标题页</title>
    </head>
    <body>
        
    <form id="Form1" runat="server">
            
            
    <h2>Languages and Buttons</h2>
            
            
    <div>                    
                
    <asp:dropdownlist ID="ToolbarStyle" Runat="Server" />
                
    <asp:dropdownlist ID="Language" Runat="Server" />
                
    <asp:Button ID="ConfigureButton" Text="Configure" runat="Server" OnClick="ConfigureButton_Click" />

                
    <br />
            
                
    <FTB:FreeTextBox id="FreeTextBox1"  
                Focus
    ="true"
                toolbarlayout
    ="ParagraphMenu,FontFacesMenu,FontSizesMenu,FontForeColorsMenu,FontForeColorPicker,FontBackColorsMenu,
    FontBackColorPicker|Bold,Italic,Underline,Strikethrough,Superscript,Subscript,RemoveFormat|JustifyLeft,JustifyRight,JustifyCenter,
    JustifyFull;BulletedList,NumberedList,Indent,Outdent;CreateLink,Unlink,InsertImage|Cut,Copy,Paste,Delete;Undo,Redo,Print,Save|
    SymbolsMenu,StylesMenu,InsertHtmlMenu|InsertRule,InsertDate,InsertTime|InsertTable,EditTable;InsertTableRowAfter,
    InsertTableRowBefore,DeleteTableRow;InsertTableColumnAfter,InsertTableColumnBefore,DeleteTableColumn|InsertForm,InsertTextBox,
    InsertTextArea,InsertRadioButton,InsertCheckBox,InsertDropDownList,InsertButton|InsertDiv,EditStyle,InsertImageFromGallery,
    Preview,SelectAll,WordClean,NetSpell"

                ImageGalleryPath 
    = "~/image/upload"
                ImageGalleryUrl 
    = "ftb.imagegallery.aspx?rif={0}&cif={0}"
                Language
    ="zh-CN"  
                ToolbarStyleConfiguration
    ="Office2003" 
                OnSaveClick
    ="SaveButton_Click" 
                runat
    ="Server">
                
                
    </FTB:FreeTextBox>
                
    <asp:LinkButton ID="LinkButton1" runat="server"/>
                
    <asp:Button id="SaveButton" Text="Save" runat="server" OnClick="SaveButton_Click" />
            
    </div>
            
            
    <div>
                
    <asp:Literal id="Output" runat="server" />
                
            
    </div>
        
    </form>

    </body>
    </html>

    其中要注意的是,由于ASP.NET不是默认会自动产生_doPostBack方法,因此,如果采用FTB的默认Save按钮操作,可能会报告对象不存在错误,因此,可以在网页中添加一行<asp:LinkButton ID="LinkButton1" runat="server"/>来强制要求产生_doPostBack方法。Language属性设置要求放置在toolbarlayout之后设置,否则可能产生不了效果。

    Default.aspx.cs

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Collections.Specialized;
    public partial class _Default : System.Web.UI.Page 
    {
        
    protected void Page_Load(object sender, EventArgs e)
        {
            ToolbarStyle.DataSource 
    = Enum.GetNames(typeof(FreeTextBoxControls.ToolbarStyleConfiguration));
            
    if (!IsPostBack)
            {

                ToolbarStyle.DataSource 
    = Enum.GetNames(typeof(FreeTextBoxControls.ToolbarStyleConfiguration));
                ToolbarStyle.DataBind();

                FreeTextBoxControls.Support.ResourceManager rm 
    = new FreeTextBoxControls.Support.ResourceManager();
                NameValueCollection languages 
    = rm.GetSupportedLanguages();

                
    foreach (string key in languages)
                {
                    Language.Items.Add(
    new ListItem(key, languages[key]));
                }

                FreeTextBox1.Text 
    = "<p>some <b>Bold</b> and <u>underlined</u> and <font color="#008000">colored</font> text<p><ul><li>bulleted list 1</li></ul>";
            }
        }

        
    protected void ConfigureButton_Click(object sender, EventArgs e)
        {
            FreeTextBox1.ToolbarStyleConfiguration 
    = (FreeTextBoxControls.ToolbarStyleConfiguration)Enum.Parse(typeof(FreeTextBoxControls.ToolbarStyleConfiguration), ToolbarStyle.SelectedValue);
            FreeTextBox1.Language 
    = Language.SelectedValue;
        }
        
    protected void SaveButton_Click(object sender, EventArgs e)
        {
            Output.Text 
    = FreeTextBox1.Text;
        }
    }

     

    ImageGallery的使用

    将压缩包中的ftb.imagegallery.aspx拷贝到工程目录下,然后修改该文件以配置相应的图片上传属性。

    <%@ Page Language="C#" ValidateRequest="false" Trace="false" %>
    <%@ Register TagPrefix="FTB" Namespace="FreeTextBoxControls" Assembly="FreeTextBox" %>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        
    <title>Image Gallery</title>
    </head>
    <body>

        
    <form id="Form1" runat="server" enctype="multipart/form-data">  
        
            
    <FTB:ImageGallery id="ImageGallery1" 
                JavaScriptLocation
    ="InternalResource" 
                UtilityImagesLocation
    ="InternalResource" 
                SupportFolder
    ="~/aspnet_client/FreeTextBox/"
                AllowImageDelete
    ="true" 
                AllowImageUpload
    ="true" 
                AllowDirectoryCreate
    ="false" 
                AllowDirectoryDelete
    ="false" 
                runat
    ="Server" />
            
        
    </form>

    </body>
    </html>