【问题标题】:How to change background of CKeditor from code behind C#如何从 C# 后面的代码更改 CKeditor 的背景
【发布时间】:2016-10-31 05:15:35
【问题描述】:

真的很简单的问题。如何从 C# 更改 CKeditor 的背景颜色?

如何在 C# 中获取 CKeditor 的实例?可能我不能?

我有一个 gridview,其中包含许多 textareas (asp:textbox) 控件,所有这些控件都使用 CKeditor,通过 CSSclass 属性,它工作得很好!但现在我想动态地将它们的一两个或所有背景颜色更改为LightYellow

我尝试直接更改asp:textbox 的背景,但它当然不起作用,因为它对CKeditor 本身“隐藏”。

请问还有什么建议吗?

更新

我已经为 ASP.net 下载了 CKEditor,它也不起作用,因为它还会在后台自动创建一个 textarea 元素 - 实际上与在本机使用 CKeditor 相同CSSclass="".

引用 C# 中的控件,我现在可以这样做,这很棒,因此我可以获取数据并在我的数据库中使用它,但我仍然无法更改 CKeditor 的背景。 CKeditor 的 BODY 元素(通过 FireBug 测试)是我需要更改的元素,但是如何从 C# 更改?

再次感谢

【问题讨论】:

  • config.js会有一个选项config.uiColor = 'your-color-code';
  • @Webruster 谢谢,但我需要从服务器更改背景,而不是客户端,即:使用 C#。您的建议会针对我程序中的每个 CKeditor 实例进行更改。还是谢谢
  • CKEDITOR.addCss(' body{ background:red; } '); 有效,但它会更改页面上所有编辑器的背景颜色。
  • @Fandango68 您能否发布您的 ASP.NET 代码,展示您如何在 GridView 中使用 CKEditor?另外,您使用的是哪个版本的 CKEditor?

标签: c# asp.net background ckeditor


【解决方案1】:

首先,确保您已通过 Nuget 安装了 CKEditorCkeditorForASP.NET 软件包。

然后,创建一个 editor.css 文件,该文件将仅包含与编辑器相关的样式,例如:

.lightYellow {
   background-color: lightyellow;
}

在您的网格视图上,绑定到 OnRowDataBound 事件并正确指定 CKEditor 脚本的基本路径。

<asp:GridView ID="EditorGridView" runat="server" OnRowDataBound="EditorGridView_RowDataBound">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <CKEditor:CKEditorControl ID="Editor" runat="server" BasePath="~/Scripts/ckeditor" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

然后你就可以改变身体颜色如下:

if (e.Row.RowType == DataControlRowType.DataRow)
{
    CKEditorControl editor = (CKEditorControl)e.Row.FindControl("Editor");
    editor.BodyClass = "lightYellow";
    editor.ContentsCss = ResolveUrl("~/Content/editor.css");
}

【讨论】:

  • 只有一个问题。在不创建单独的 .css 文件的情况下如何做同样的事情?
  • 我尝试了其他选项 - 不包括 javascript 使用 - 似乎这是使用 C# 的唯一方法。
猜你喜欢
  • 2010-09-05
  • 2020-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-02
  • 1970-01-01
相关资源
最近更新 更多