我怎样才能得到一个C#ASP.Net应用程序中的TinyMCE的HTML内容? [英] How can I get the tinymce HTML content from within a C# ASP.Net application?

查看:574
本文介绍了我怎样才能得到一个C#ASP.Net应用程序中的TinyMCE的HTML内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TinyMCE的编辑器,我想抓住我的C#ASPX code内的编辑器的HTML内容 - 但我不是这样做的正确的方式完全确定

有人可以请建议最佳实践?

我知道我可以通过从JavaScript调用此获得HTML内容...但我怎么会传递结果返回给我的ASP.NET的C#为存储在数据库中,例如:

  tinymce.activeEditor.getContent()


解决方案

设置页面验证请求,假第一:

 <%@页ValidateRequest =false的..

然后添加一个ID和RUNAT属性为您的textarea:

 < textarea的ID =txtEditor=服务器...>< / textarea的>

比如说点击一个按钮,你想抓住这样的信息:

 保护无效的button1_Click(对象发件人,EventArgs的发送)
    {
        字符串的text1 = txtEditor.InnerHtml; //包括HTMLS
        字符串文本2 = txtEditor.InnerText; //仅仅是纯文本        //的数据存储到数据库这里
    }

您还可以添加的第一行到您的web.config文件,如果您使用的是.NET Framework 4的+

 <&的System.Web GT;
     <页validateRequest =假/>
     <的httpRuntime requestValidationMode =2.0/>
     ....

如果你不希望有一个全球范围内,你只能使用web.config文件以及它指向的页面:

只需添加在你的web.config文件之前尽头这一块的< /结构>

  ....
 <位置路径=WebForm2.aspx> <! - 在这里添加您的网页路径 - >
  <&的System.Web GT;
    <页validateRequest =假/>
    <的httpRuntime requestValidationMode =2.0/>
  < /system.web>
 < /地点>
< /结构>

I have a tinymce editor and I am wanting to grab the HTML contents of the editor within my C# ASPX code - but I am not entirely sure on the right way of doing this?

Can somebody please suggest a best practice?

I know I can get the HTML Content by calling this from javascript...but how would I pass that result back to my ASP.NET C# for storing in a database for example:

tinymce.activeEditor.getContent()

解决方案

Set your Page validate request to false first:

<%@ Page ValidateRequest="false" ..

then add an id and runat property to your textarea:

<textarea id="txtEditor" runat="server" ... ></textarea>

Let's say on a button click you want to grab the information like this:

    protected void Button1_Click(object sender, EventArgs e)
    {
        string text1 = txtEditor.InnerHtml;  //includes HTMLs
        string text2 = txtEditor.InnerText;  //just plain text

        //store the value into the database here
    }

You could also add the first line into your web.config file if your are using .NET Framework 4 +

<system.web>
     <pages validateRequest="false" />
     <httpRuntime requestValidationMode="2.0" />
     ....

And if you do not want to have that globally you could point it to the page only using web.config as well:

Just add this one at the very end of your web.config file just before the </configuration>

 ....
 <location path="WebForm2.aspx"> <!-- add your page path here -->
  <system.web>
    <pages validateRequest="false" />
    <httpRuntime requestValidationMode="2.0" />
  </system.web>
 </location>
</configuration>

这篇关于我怎样才能得到一个C#ASP.Net应用程序中的TinyMCE的HTML内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆