0

I am using tinyMCE for a nice text editor, but now I am trying to get the text I've inserted, I would like to know how that is possible. I've tried:

HTML CODE:

<textarea id="TA_MessageInput"></textarea>
<asp:HiddenField id="HF_MessageInput" ClientIDMode="static" runat="server"/>

JAVASCRIPT CODE:

<script type="text/javascript">
    function getTinyMCEText() {
        document.getElementById('<%= HF_MessageInput.ClientID %>').Value = tinyMCE.activeEditor.getContent();
        alert(document.getElementById('<%= HF_MessageInput.ClientID %>').Value);
    };
</script>

ASP.NET CODE:

ScriptManager.RegisterClientScriptBlock(this, GetType(), "", "getTinyMCEText()", true);
String text = HF_MessageInput.Value;

The javascript gives me the alert that the tag has been filled, unfortunately it did not for ASP.NET, this says it is still null.

EDIT

OnClientClick="tinyMCE.triggerSave(false,true);"

^ that was the problem... :)

runefist
  • 543
  • 1
  • 8
  • 19
  • You need to understand the difference between _server-side_ code and _client-side_ code. Your whole approach cannot possibly work. You need AJAX (or just assign the value before submitting). – SLaks Mar 08 '16 at 19:22
  • Explain what you're trying to accomplish here. Your question doesn't make sense. – Rick S Mar 08 '16 at 19:22
  • Since I cannot make the textarea that is needed for the TinyMCE runat="server", I want to pass the text I've inserted to something else so my server can read the data and put it in the database. – runefist Mar 08 '16 at 19:24
  • What is the reason why you can't use runat="server"?? Should work just fine. This is the key property to get it to work `ClientIDMode="Static"` – Rick S Mar 08 '16 at 19:27

1 Answers1

0

I think you might be approaching this incorrectly. The TinyMCE text area can be accessed from your server side code without having to use javascript. For example:

<asp:TextBox ID="TA_MessageInput" runat="server" ClientIDMode="Static"
    TextMode="MultiLine" Rows="30" style="width:95%" CssClass="tinymce" />

Then from your server side code, you would access the value of the TinyMCE field like any other Textbox field (depends on VB/C#):

var textValue = TA_MessageInput.InnerHtml

If you search for "ASP.NET TinyMCE", you should be able to find a lot of working examples. For example: http://www.intertech.com/Blog/integrating-tinymce-4-0b3-into-an-asp-net-4-0-project/

John Lee
  • 1,357
  • 1
  • 13
  • 26
  • This did not work D: TA_MessageInput.Text just says it is and empty string – runefist Mar 08 '16 at 19:53
  • Sorry, that should be .InnerHtml (or InnerText). Also, you may need to set ValidateRequest to false on the page. This is due to the embedded html in the field. There is a similar question and answer here: – John Lee Mar 08 '16 at 21:18
  • http://stackoverflow.com/questions/24643595/how-can-i-get-the-tinymce-html-content-from-within-a-c-sharp-asp-net-application – John Lee Mar 08 '16 at 21:18