简体   繁体   English

如何从C#背后的代码更改CKeditor的背景

[英]How to change background of CKeditor from code behind C#

Simple question really. 真的很简单。 How can I change the background color of the CKeditor from C#? 如何从C#更改CKeditor的背景颜色?

How do I get an instance of CKeditor in C#? 如何在C#中获取CKeditor实例? Probably I cannot? 可能我不能吗?

I have a gridview with lots of textareas (asp:textbox) controls all using the CKeditor, via the CSSclass property, and it works great! 我有一个带有很多textareas(asp:textbox)控件的gridview,它们都通过CSSclass通过CSSclass属性使用,并且效果很好! But now I want to dynamically change one or two, or all of their background colours to something like LightYellow . 但是,现在我想将一种或两种或所有它们的背景颜色动态更改为类似LightYellow颜色。

I've tried to directly change the background of the asp:textbox , but it doesn't work of course because that's "hidden" from the CKeditor itself. 我试图直接更改asp:textbox的背景,但是它当然不起作用,因为这是CKeditor本身的“隐藏”。

Any other tips please? 还有其他提示吗?

UPDATE 更新

I've downloaded the CKEditor for ASP.net and it too does not work , as it also creates a textarea element in the background automatically - effectively the same as using the CKeditor natively with CSSclass="" . 我已经下载了用于ASP.net的CKEditor,它也无法正常工作 ,因为它还会在后台自动创建textarea元素-有效地与在CSSclass=""本地使用CSSclass=""相同。

Referencing the control in C#, I can do that now, which is great so I can get the data and use it in my database, but I still cannot change the CKeditor's background. 引用C#中的控件,我现在可以执行此操作,这很棒,因此我可以获取数据并在数据库中使用它,但是仍然无法更改CKeditor的背景。 The CKeditor's BODY element (tested via FireBug), is the one I need to change, but how from C#? CKeditor的BODY元素(通过FireBug测试)是我需要更改的元素,但是如何从C#中更改呢?

Thanks again 再次感谢

First, be sure you have installed both CKEditor and CkeditorForASP.NET packages via Nuget. 首先,请确保您已通过Nuget安装了CKEditorCkeditorForASP.NET软件包。

Afterwards, create an editor.css file which will contain only editor related styles such as: 然后,创建一个editor.css文件,该文件将仅包含与编辑器相关的样式,例如:

.lightYellow {
   background-color: lightyellow;
}

On your grid view, bind to OnRowDataBound event and specify base path of CKEditor scripts correctly. 在网格视图上,绑定到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>

Then you will be able to change the body color as follows: 然后,您将能够按照以下方式更改主体颜色:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM