如何使用asp按钮保存tinymce

How to save tinymce using asp button

本文关键字:保存 tinymce 按钮 asp 何使用      更新时间:2023-09-26

我正在使用 asp.net 和c#来构建一个可以上传,编辑,保存文件的网站。我使用 tinymce 作为文本编辑器,但问题是我不知道如何在 tinymce 中配置保存插件。我添加了asp按钮用作保存按钮,但是如何配置它以保存到文件.html中?

JavaScript 用 TexEditor 替换 Tiny :

           $('#<%=btnsave.ClientID%>').show()  //save button
           tinymce.init({selector: "textarea"});   //replace texteditor

这是标记代码:

            <textarea name="textarea" cols="100" rows="5" style="visibility: hidden;">
            </textarea>
            <br /><asp:Button Text="Save" runat="server" ID="btnsave" style="display:none;" onclick="btnsave_Click" />

这在代码隐藏中

           protected void btnsave_Click(object sender, EventArgs e)
              {
                string path = Server.MapPath("~/WordExcelPPointToHtml/test.html");
                File.WriteAllText(path,HtmlTextArea);     //this line have error!!
              }

谁能帮我解决这个问题?提前谢谢。急切地等待答案。

您需要将

html 控件替换为 ASP.NET Web 控件,您将能够在代码隐藏中以编程方式访问该值。

例如

<asp:TextBox ID="txt" Name="textarea" Columns="100" Rows="5" TextMode="MultiLine" runat="Server"></asp:TextBox>

在后面的代码中:

protected void btnsave_Click(object sender, EventArgs e)
{
    string path = Server.MapPath("~/WordExcelPPointToHtml/test.html");
    File.WriteAllText(path, txt.Text);
}

您还应该考虑btnSave_Click中的一些错误处理