如何更改div的内部html

发布于 2024-11-01 17:52:29 字数 820 浏览 0 评论 0原文

我有一个 div 和一个 html 编辑器,并尝试:

  1. 将 div 内部 html 添加到 编辑。 (完成)
  2. 然后在编辑器中完成任何更改 被保存回div中。

这是后台代码:

protected void Page_Load(object sender, EventArgs e) 
{
    Editor.Content = cvDiv.InnerHtml;
}

protected void preview(object sender, EventArgs e) //this is an onclick event
{
    cvDiv.InnerHtml = Editor.Content;
}

和编辑器的代码:

<asp:ScriptManager runat="server" />
<cc1:Editor ID="Editor" runat="server" OnContentChanged="preview"  />
<asp:Button runat="server" ID="eButton" CssClass="eButton" Text="Edit" OnClick="Edit" />// this is the button that is supposed to save

但它不起作用。

所以我想做的是将编辑器中所做的任何更改保存到 div

使用 asp.net 3.5 和 ajax 工具包编辑器。

提前致谢。

i have a div and an html editor and trying to:

  1. add the div inner html to the
    editor. (thats done)
  2. then any changes done in the editor
    is saved back in the div.

here is the backcode :

protected void Page_Load(object sender, EventArgs e) 
{
    Editor.Content = cvDiv.InnerHtml;
}

protected void preview(object sender, EventArgs e) //this is an onclick event
{
    cvDiv.InnerHtml = Editor.Content;
}

and the code for the editor:

<asp:ScriptManager runat="server" />
<cc1:Editor ID="Editor" runat="server" OnContentChanged="preview"  />
<asp:Button runat="server" ID="eButton" CssClass="eButton" Text="Edit" OnClick="Edit" />// this is the button that is supposed to save

but it doesnt work.

so what i am trying to do is save whatever changes made in the editor to the div

using asp.net 3.5, and the ajax toolkit editor.

thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生活了然无味 2024-11-08 17:52:29

这是我为向您展示有效代码而制作的示例。

ASPX

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"></asp:ScriptManager>
        <asp:TextBox id="editor" runat="server" AutoPostBack="true"></asp:TextBox>
        <asp:Button ID="Save" runat="server" OnClick="SaveChange" Text="Save" />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" >
            <ContentTemplate>
                <div id="preview" runat="server"></div>    
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="editor" EventName="TextChanged" />
            </Triggers>
        </asp:UpdatePanel>
    </form>
</body>
</html>

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)
    {
        if(!IsPostBack) editor.Text = preview.InnerHtml;
        else preview.InnerHtml = editor.Text;

    }

    protected void SaveChange(object sender, EventArgs e)
    {
        string thingsToSave = preview.InnerHtml;
        //Save to db/file/xml   

    }

}

This is an example i've made to show you a working code.

ASPX

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"></asp:ScriptManager>
        <asp:TextBox id="editor" runat="server" AutoPostBack="true"></asp:TextBox>
        <asp:Button ID="Save" runat="server" OnClick="SaveChange" Text="Save" />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" >
            <ContentTemplate>
                <div id="preview" runat="server"></div>    
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="editor" EventName="TextChanged" />
            </Triggers>
        </asp:UpdatePanel>
    </form>
</body>
</html>

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)
    {
        if(!IsPostBack) editor.Text = preview.InnerHtml;
        else preview.InnerHtml = editor.Text;

    }

    protected void SaveChange(object sender, EventArgs e)
    {
        string thingsToSave = preview.InnerHtml;
        //Save to db/file/xml   

    }

}
星星的轨迹 2024-11-08 17:52:29

您可以尝试使用 Literal 控件而不是服务器端

吗?

Can you try using Literal control rather than a server side <div /> ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文