2012-10-15 139 views
0

我需要從ckeditor按鈕到達我的codebehind點擊事件。 我與此代碼爲我定製的CKEditor按鈕嘗試(函數(){用ckEditor工具欄按鈕調用Asp.Net按鈕點擊事件

//Section 1 : Code to execute when the toolbar button is pressed 
    var a = { 
     exec: function (editor) { 
      var testObj = editor.parentNode; 
      var count = 1; 
      while (testObj.getAttribute('id') != "form1") { 
       testObj = testObj.parentNode; 
      } 
      testObj.getElementById('<%= btnUserControls.ClientID %>').click(); 
     } 
    }, 
//Section 2 : Create the button and add the functionality to it 
    b='usercontrols'; 
    CKEDITOR.plugins.add(b,{ 
     init:function(editor){ 
      editor.addCommand(b,a); 
      editor.ui.addButton('usercontrols', { 
       label:'User Controls', 
       icon: this.path + 'ascx.png', 
       command:b 
      }); 
     } 
    }); 
})(); 

但是我覺得這個代碼不能達到我的Asp.Net button.Where我錯了?謝謝。

回答

0

這是很難說清楚不知道你的.aspx代碼,但最有可能的形式的ID是在客戶端而不是「form1的」你可以試試modyfing你這樣的代碼:

... 
var a = { 
    exec: function (editor) { 
     document.getElementById('<%= btnUserControls.ClientID %>').clic(); 
    } 
} 
... 

也不像這個:

... 
var a = { 
    exec: function (editor) { 
     __doPostBack('<%= btnUserControls.UniqueID %>', ''); 
    } 
} 
... 
+0

他們並沒有解決我的problem.Also我想這代碼'__doPostBack( '<%= btnUserControls.ClientID%>',加入 'onClick');' –

+0

@BahadırYılmaz有你試着用'__doPostBack('<%= btnUserControls .UniqueID%>','');'(在我的回答中,這是一個明顯的錯誤,我編輯過它)? – tpeczek

1

如果你想呼籲ASP.NET按鈕服務器端單擊事件,那麼你需要這樣執行腳本:__doPostBack('<%= btnUserControls.UniqueID %>', ''); 注:這是必須使用的UniqueID而不是客戶端ID。

+0

Thnx爲您的帖子!解決了! –