zoukankan      html  css  js  c++  java
  • FCKeditor只读与编辑状态切换的不完全解决方案[原创]

    1、首先在FCKeditor目录下的fckconfig.js文件,添加Readonly模式(可以将页面中的FCKeditor控件的ToolbarSets属性设置为“Readonly”,需要编辑时在代码中更改为“Default”):

    FCKConfig.ToolbarSets["Readonly"] = [
    [
    'Preview','Print']
    ] ;

    2、FCKeditor两种模式切换的函数:

    private void ModFCKEditor(Boolean YN)
    {
    if (YN) //可编辑状态
    {
    string jsReadOnly = @"function FCKeditor_OnComplete( editor )
    {
    editor.EditorDocument.body.contentEditable = true;
    editor.EditMode=FCK_EDITMODE_SOURCE;
    editor.ToolbarSet.RefreshModeState();
    editor.EditMode=FCK_EDITMODE_WYSIWYG;
    editor.ToolbarSet.RefreshModeState();
    }
    ";
    ClientScript.RegisterStartupScript(
    this.GetType(), "", "<script language=javascript>" + jsReadOnly + "</script>");
    }
    else //只读状态
    {
    string jsEnable = @"function FCKeditor_OnComplete( editor )
    {
    editor.EditorDocument.body.contentEditable = false;
    editor.EditMode=FCK_EDITMODE_SOURCE;
    editor.ToolbarSet.RefreshModeState();
    editor.EditMode=FCK_EDITMODE_WYSIWYG;
    editor.ToolbarSet.RefreshModeState();
    }
    ";
    ClientScript.RegisterStartupScript(
    this.GetType(), "", "<script language=javascript>" + jsEnable + "</script>");
    }
    }

    3、用ViewState控制FCKEditor的状态(记得在程序中控制状态,然后在需要的时候调用:this.ModFCKEditor(enableEditor);):

    public Boolean enableEditor
    {
    get { return ViewState["enableEditor"] == null ? false : (Boolean)ViewState["enableEditor"]; }
    set { ViewState["enableEditor"] = value; }
    }

    4、我的做法是将FCKeditor放在div里面,页面加载的时候该div是隐藏的,当点击查看的时候就显示div且FCKeditor为只读状态,当点编辑按钮时将FCKeditor的ToolbarSets属性设置为“Default”,将enableEditor设置为True,再调用this.ModFCKEditor(enableEditor)

    5、数据显示我用的是GridView,控制列如下:

    <asp:TemplateField HeaderText="Operation" ItemStyle-Width="120">

    <ItemTemplate>

    <div>

    &nbsp;&nbsp;&nbsp;&nbsp;<%# DataBinder.Eval(Container.DataItem, "ID", "<a href=/ViewDocs.aspx?DOCID={0}>查看</a>")%>
    &nbsp;&nbsp;&nbsp;&nbsp;<asp:LinkButton ID="btnDeleteRow" runat="server" Text="删除" CommandArgument="<%# Container.DataItemIndex %>" CommandName="Delete" OnClientClick="Javascript:return confirm('是否确定删除此文档?');" />

    </div>
    </ItemTemplate>

    </asp:TemplateField>

    说明:查看功能转到的页面仍是当前页面,只不过此时带了参数!所以我用ViewState记录了FCKeditor的状态!

    就这么多了,希望对大家有所帮助!

  • 相关阅读:
    PHP调试总结
    vim常用命令
    Xshell
    JavaScript
    HTML+CSS
    解决VMware“该虚拟机似乎正在使用中”问题
    MVC dirname(——FILE——)
    各种编程语言中的指针和引用
    Go defer 原理和源码剖析
    软件架构定义的流派
  • 原文地址:https://www.cnblogs.com/mic86/p/1789089.html
Copyright © 2011-2022 走看看