2012-10-15 134 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为您的帖子!解决了! –