2016-03-03 60 views
0

我在更新面板中使用了TinyMCE,但它在每次部分回發後都會消失,爲什麼?它應該在任何情況下都能正常工作,即使官方網站也沒有關於它的說法。爲什麼我的控件在回發中消失?

我已經用它是這樣的:

<script type="text/javascript"> 
     tinymce.init({ 
      selector: '#<%=txtBoxBody.ClientID%>', 
      height: 200, 
      theme: 'modern', 
      plugins: [ 
       'advlist autolink lists pagebreak', 
       //'searchreplace wordcount visualblocks visualchars fullscreen', 
       'insertdatetime save contextmenu directionality', 
       ' paste textcolor textpattern print' 
      ], 
      toolbar1: 'insertfile undo redo | fontsizeselect | forecolor emoticons | fontselect emoticons | styleselect | bold italic | alignleft aligncenter alignright alignjustify', 
      //toolbar2: 'print preview media | forecolor backcolor emoticons', 
      //image_advtab: true, 
      fontsize_formats: '8pt 9pt 10pt 11pt 12pt 14pt 18pt 20pt 22pt 24pt 26pt 28pt 36pt 48pt 72pt', 
      //templates: [ 
      // { title: 'Test template 1', content: 'Test 1' }, 
      // { title: 'Test template 2', content: 'Test 2' } 
      //], 
      content_css: [ 
       '//fast.fonts.net/cssapi/e6dc9b99-64fe-4292-ad98-6974f93cd2a2.css', 
       '//www.tinymce.com/css/codepen.min.css' 
      ] 
     }); 


    </script> 

on this txtbox 
<asp:TextBox runat="server" ID="txtBoxBody" Rows="20" Columns="25" TextMode="MultiLine" CssClass="form-control"></asp:TextBox> 

它出現在第一頁加載,但後門柱沒有回來 UPDATE:

它試圖這樣在頁面加載事件

//ScriptManager.RegisterStartupScript(this, this.GetType(), txtBoxBody.UniqueID + "Add", "tinyMCE.execCommand('mceAddEditor', true,'" + txtBoxBody.ClientID + "');", true); 
     //ScriptManager.RegisterOnSubmitStatement(this, this.GetType(), txtBoxBody.UniqueID + "Remove", "tinyMCE.execCommand('mceRemoveEditor', true,'" + txtBoxBody.ClientID + "');"); 

它使其可見,但使形式充滿麻煩,即全面回發和不同的問題。

更新:我已經使用JavaScript的pageLoad並把這個代碼裏面,但然後插件消失。

更新:那麼我想什麼的Piyush建議

<script type="text/javascript"> 
    function SetEditor() { 
     tinymce.init({ 
      selector: '#<%=txtBoxBody.ClientID%>', 
      height: 200, 
      theme: 'modern', 
      plugins: [ 
       'advlist autolink lists pagebreak', 
       //'searchreplace wordcount visualblocks visualchars fullscreen', 
       'insertdatetime save contextmenu directionality', 
       ' paste textcolor textpattern print' 
      ], 
      toolbar1: 'insertfile undo redo | fontsizeselect | forecolor emoticons | fontselect emoticons | styleselect | bold italic | alignleft aligncenter alignright alignjustify', 
      //toolbar2: 'print preview media | forecolor backcolor emoticons', 
      //image_advtab: true, 
      fontsize_formats: '8pt 9pt 10pt 11pt 12pt 14pt 18pt 20pt 22pt 24pt 26pt 28pt 36pt 48pt 72pt', 
      //templates: [ 
      // { title: 'Test template 1', content: 'Test 1' }, 
      // { title: 'Test template 2', content: 'Test 2' } 
      //], 
      content_css: [ 
       '//fast.fonts.net/cssapi/e6dc9b99-64fe-4292-ad98-6974f93cd2a2.css', 
       '//www.tinymce.com/css/codepen.min.css' 
      ] 
     }); 


    } 
</script> 
<script type="text/javascript"> 
    // below will execute first time when page load 
    SetEditor(); 

    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); 

    function EndRequestHandler(sender, args) { 
     // this will execute on partial postback 
     SetEditor(); 
    } 
</script> 

但同樣的問題

回答

0

要解決此問題,請按照下列步驟操作,

  1. 創建setEditor的JavaScript功能如下,

    <script type="text/javascript"> 
    function SetEditor() { 
        tinymce.init({ 
        ... 
        }); 
    } 
    </script> 
    
  2. body標籤結束前,加入下面的腳本,

    <script type="text/javascript"> 
        // below will execute first time when page load 
        SetEditor(); 
    
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); 
    
        function EndRequestHandler(sender, args) { 
         // this will execute on partial postback 
         SetEditor();   
        } 
    </script> 
    
+0

不工作sir – Stacky

+0

那麼,我試着用同樣的方式,它爲我工作。你把所有這些東西放在.aspx文件中了嗎? –

+0

是的,先生,我做了,它不起作用 – Stacky

0

包裹你的初始化函數中的 然後確保註冊您初始化函數使用ScriptManager 像例如 ScriptManager.RegisterStartupScript(這一點。頁面, this.Page.GetType(),mce.ClientID,「pageLoad();」,true);

+0

好吧,它的工作原理,但它會導致完整的回頁面在每一次點擊甚至點擊甚至 – Stacky

0

@Piyush非常有幫助,稍做修改就解決了這個問題。

ScriptManager.RegisterStartupScript(this, this.GetType(), txtBoxBody.UniqueID + "Add", "tinyMCE.execCommand('mceAddEditor', true,'" + txtBoxBody.ClientID + "');", true); 
    ScriptManager.RegisterOnSubmitStatement(this, this.GetType(), txtBoxBody.UniqueID + "Remove", "tinyMCE.execCommand('mceRemoveEditor', true,'" + txtBoxBody.ClientID + "');"); 
相關問題