我目前正在为网站实施 CMS。我使用 Javascript、jQuery、C# 等的经验非常少。我主要处理 Java、SQL 和 C++。我的问题是我在页面上加载了 CKEditor 实例。我能够将我存储在我的数据库中的 HTML 加载到 CKEditor 窗口中,但是我无法从 CKEditor 中获取我已经更改的值。
默认.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>
默认.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);
}
}
我已经测试并且知道我正在从该SaveButton_Click
方法写入数据库。我注意到的一件事是我可以显示一条静态警报消息,例如,alert("message");
但我的代码中的任何一行都不会弹出警报窗口。
在进行此设置方面的任何帮助,以便我可以使用类结构写入我的数据库,或者只是GetContents()
开始工作,将不胜感激。