Customizing a TinyMCE Text Box Element

On a webpage, I'm trying to initialize TinyMCE for a specific asp: textbox web control.

This is javascript in title:

  tinyMCE.init({
        mode: "exact",
        elements: '<% = txtBody.ClientID %>',

The problem is that the txtBody control is created inside the DetailsView control template:

<asp:TemplateField HeaderText="Body" SortExpression="Body">           
   <EditItemTemplate>
      <asp:TextBox ID="txtBody" runat="server" Rows="10" TextMode="MultiLine" Width="100%" Height="400px"></asp:TextBox>                  
   </EditItemTemplate>
</asp:TemplateField>

So txtBody.ClientID cannot find it at boot time.

+3
source share
3 answers

We know that I solved it as follows:

I added the OnInit = "txtBody_OnInit" event to the text box:

protected void txtBody_OnInit(object sender, EventArgs e)
{
    ClientScript.RegisterStartupScript(GetType(), "SetEditor", string.Format("SetEditor('{0}');", ((TextBox)sender).ClientID), true);
}

Then add tinymce initialization inside the SetEditor (theID) JavaScript editor function.

This is not an ideal answer, so if there is a better answer, I will accept it.

0
source

tinyMCE onload. , JS,

document.onload = function() { tinyMCE.init ...... }

<head> .

0

You can use TinyMce server control instead of a simple TextBox. You can find here or another, written by me, here .

0
source

Source: https://habr.com/ru/post/1726718/


All Articles