I am currently in the process of integrating a content management system (CMS) for a website. My familiarity with Javascript, jQuery, C#, etc., is limited as I primarily work with Java, SQL, and C++. My query pertains to the CKEditor instance loaded on the page. While I can successfully load the HTML stored in my database into the CKEditor window, I am facing difficulty extracting the modified values from CKEditor.
Default.aspx
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>
<asp:Content ID="Head1" runat="server" ContentPlaceHolderID="head" >
<%--Javascript funciton for Display Contents button--%>
<script type="text/javascript">
function GetContents() {
// Display the value of CKEditor into an alert
alert(CKEDITOR.instances.CKEditor1.getData());
//Have also tried alert(CKEDITOR.instances[CKEditor1].getData());
}
</script>
</asp:Content>
<asp:Content ID="form1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<CKEditor:CKEditorControl ID="CKEditor1" runat="server">
</CKEditor:CKEditorControl>
<%--Button that executes the command to store updated data into database--%>
<asp:Button ID="SaveButton" runat="server" Text="Save Changes"
onclick="SaveButton_Click" />
<button type="button" onclick="GetContents()">Display Contents</button>
</asp:Content>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Retrieve HTML
HomePageHTML hp = HomePageHTMLAccess.GetHomPageHTML();
//Does HTML exist?
if (hp.HTML != null)
{
PopulateControls(hp);
}
}
//Method to load html from database into webpage
private void PopulateControls(HomePageHTML hp)
{
//Display html
CKEditor1.Text = hp.HTML;
}
//Method to save the updated html into the database
protected void SaveButton_Click(object sender, EventArgs e)
{
string text1 = CKEditor1.Text;
HomePageHTMLAccess.UpdateHomePageHTML(text1);
}
}
I have tested and know that I am writing to the database from the SaveButton_Click
method. One thing that I have noticed is that I can display a static alert message, such as alert("message");
but no alert window pops up at all with either of the lines in my code.
Any assistance in configuring this setup to write to the database using the class structure or in getting GetContents()
to function properly would be highly appreciated.