What should be a simple integration of tinyMCE in a Visual Studio C# application: I cannot get the HTML text after the user edits the content. I've tried all the tips and tricks I can find online. I must be missing something?
FIrst using straight jQuery to read the data after #submit button, return the content that was pre-set from code-behind, NOT what the user just changed.
First in my @ Page is set
EnableEventValidation="false" ValidateRequest="false"
<script src="Scripts/tinymce/tinymce.min.js"></script>
<script src="Scripts/tinymce/jquery.tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector: 'div#<%= txtPDFHeaderMessage.ClientID %>',
height: 250,
menubar: true,
plugins: [
'advlist autolink lists link image charmap print preview anchor textcolor',
'searchreplace visualblocks code fullscreen',
'insertdatetime media table paste code help wordcount'
],
toolbar: 'undo redo | formatselect | bold italic backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat | help',
content_css: [
'//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
'//www.tiny.cloud/css/codepen.min.css'
]
});
$(document).ready(function() {
//alert('ready');
$('#btnSave').click(function () {
var thisPDFHeaderMessage;
thisPDFHeaderMessage= $('#<%= txtPDFHeaderMessage.ClientID %>').val(); // This return original content prior to editing.
thisPDFHeaderMessage = tinyMCE.activeEditor.getContent();
// active Editor.getContent() works...but I will have two text areas in my final solution.
thisPDFHeaderMessage = tinymce.get($('#<%= txtPDFHeaderMessage.ClientID %>')).getContent();
// this crashes...0x800a138f - JavaScript runtime error: Unable to get property 'getContent' of undefined or null reference
alert('HERE ' + thisPDFHeaderMessage);
});
});
</script>
<label for="txtPDFHeaderMessage" style="margin-top:10px;"">Quote Intro Message</label>
<div id="txtPDFHeaderMessage" class="mceEditor" runat="server"></div>
<br />
<button class="btn btn-primary" id="btnSave" value='0'><i class="glyphicon glyphicon-film icon-white"></i> Save</button>
I initialize the value of the as follows:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtPDFHeaderMessage.InnerHtml = "Hello Testing";
}
}
Not sure what to try next?
User contributions licensed under CC BY-SA 3.0