Reputation: 5690
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()
Upvotes: 0
Views: 7312
Reputation: 2592
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>
Upvotes: 1
Reputation: 1874
Assuming you've bound TinyMCE to a textarea with runat="server"
, then in C# you can access the HTML via the textarea's InnerHtml
property.
Upvotes: 1