<< Click to Display Table of Contents >> CKEditor - Editando em html |
![]() ![]() ![]() |
Tela
aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Digite aqui</h1>
<div style="width: 50%">
<CKEditor:CKEditorControl ID="CKEditor1" BasePath="~/ckeditor" runat="server"></CKEditor:CKEditorControl>
</div>
<asp:Button ID="btMudarCodigo" runat="server" Text="Mudar codigo" OnClick="btMudarCodigo_Click" />
<asp:Button ID="btLerCodigo" runat="server" Text="Ler codigo" OnClick="btLerCodigo_Click" />
</div>
<hr />
<asp:TextBox ID="txtCodigo" runat="server" Rows="10" TextMode="MultiLine" Width="736px"></asp:TextBox>
<hr />
<asp:Literal ID="literal" runat="server">
</asp:Literal>
</form>
</body>
</html>
cs
using System;
namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// selecione quais operações estão visiveis (para ver todas, veja site do CKEditor)
CKEditor1.config.toolbar = new object[]
{
new object[] { "Source", "-", "Preview", "-", "Templates" },
new object[] { "Cut", "Copy", "Paste", "PasteText", "PasteFromWord", "-", "SpellChecker", "Scayt" },
new object[] { "Undo", "Redo", "-", "Find", "Replace", "-", "SelectAll", "RemoveFormat" },
"/",
new object[] { "NumberedList", "BulletedList", "-", "Outdent", "Indent", "Blockquote"},
new object[] { "JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock" },
new object[] { "Link", "Unlink", "Anchor" },
new object[] { "Image", "Table", "HorizontalRule", "SpecialChar" },
"/",
new object[] { "Bold", "Italic", "Underline", "Strike", "-", "Subscript", "Superscript", "-", "TextColor", "BGColor"},
new object[] { "Format", "Font", "FontSize" }
};
}
}
protected void btMudarCodigo_Click(object sender, EventArgs e)
{
CKEditor1.Text = "<strong>texto negrito</strong><ul><li>item1</li><li>item2</li><li>item3</li></ul><p>paragrafo</p><h4>titulo h4</h4>";
}
protected void btLerCodigo_Click(object sender, EventArgs e)
{
txtCodigo.Text = CKEditor1.Text;
literal.Text = CKEditor1.Text;
}
}
}
Web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<pages>
<controls>
<add tagPrefix="CKEditor" assembly="CKEditor.NET" namespace="CKEditor.NET"/>
</controls>
</pages>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
Projeto
Links