asp.net - insertText into a CKEditor through Code Behind -
i trying ckeditor.net insert text ckeditor
when page loads.
private sub ckeditor_load(byval sender system.object, byval e system.eventargs) handles myckeditor.load dim insertscript string insertscript = "<script type=""text/javascript"">window.ckeditor.instances.mywidget_myckeditor.inserttext(""test"");</script>" dim cmanager clientscriptmanager = parent.page.clientscript cmanager.registerstartupscript(me.gettype, "inserttext", insertscript) end sub
my page organized follows:
mypage
(aspx)mywidget
(ascx)myckeditor
(from assembly)
i getting following error:
typeerror: cannot read property 'instances' of undefined
it appears ckeditor
not around when called. if open js console , run insertscript
works desired.
i have tried attaching routine mybase.load
, me.load
no avail, , tried using window.load = insertscript
, of produce same error.
i noticed no matter do, last thing in source script initializes ckeditor
, ie
.... <script type="text/javascript">window.ckeditor.instances.mywidget_myckeditor.inserttext("test");</script> <script type="text/javascript"> //<![cdata[ window.ckeditor_basepath = '/ckeditor/'; //]]> </script> <script src="/ckeditor/ckeditor.js?t=c6hh5uf" type="text/javascript"></script> <script type="text/javascript"> //<![cdata[ var ckeditor_controls=[],ckeditor_init=[];function ckeditor_textboxencode(d,e){var f;if(typeof ckeditor=='undefined'||typeof ckeditor.instances[d]=='undefined'){f=document.getelementbyid(d);if(f)f.value=f.value.replace(/</g,'<').replace(/>/g,'>');}else{var g=ckeditor.instances[d];if(e&&(typeof page_blocksubmit=='undefined'||!page_blocksubmit)){g.destroy();f=document.getelementbyid(d);if(f)f.style.visibility='hidden';}else g.updateelement();}};(function(){if(typeof ckeditor!='undefined'){var d=document.getelementbyid('mywidget_myckeditor');if(d)d.style.visibility='hidden';}var e=function(){var f=ckeditor_controls,g=ckeditor_init,h=window.pageload,i=function(){for(var j=f.length;j--;){var k=document.getelementbyid(f[j]);if(k&&k.value&&(k.value.indexof('<')==-1||k.value.indexof('>')==-1))k.value=k.value.replace(/</g,'<').replace(/>/g,'>').replace(/&/g,'&');}if(typeof ckeditor!='undefined')for(var j=0;j<g.length;j++)g[j].call(this);};window.pageload=function(j,k){if(k.get_ispartialload())settimeout(i,0);if(h&&typeof h=='function')h.call(this,j,k);};if(typeof page_clientvalidate=='function'&&typeof ckeditor!='undefined')page_clientvalidate=ckeditor.tools.override(page_clientvalidate,function(j){return function(){for(var k in ckeditor.instances){if(document.getelementbyid(k))ckeditor.instances[k].updateelement();}return j.apply(this,arguments);};});settimeout(i,0);};if(typeof sys!='undefined'&&typeof sys.application!='undefined')sys.application.add_load(e);if(window.addeventlistener)window.addeventlistener('load',e,false);else if(window.attachevent)window.attachevent('onload',e);})();ckeditor_controls.push('mywidget_myckeditor'); ckeditor_init.push(function(){if(typeof ckeditor.instances['mywidget_myckeditor']!='undefined' || !document.getelementbyid('mywidget_myckeditor')) return;ckeditor.replace('mywidget_myckeditor',{"htmlencodeoutput" : true}); }); //]]> </script> </form> ....
all evidence suggests invoking startup script @ wrong time, don't know when "right time" invoke is.
yoy can use jquery windows.ready function below
insertscript = "<script type=""text/javascript""> <script language="javascript"> $(document).ready(function() { window.ckeditor.instances.mywidget_myckeditor.inserttext('test'); }) }) </script> "; dim cmanager clientscriptmanager = parent.page.clientscript cmanager.registerstartupscript(me.gettype, "inserttext", insertscript)
it make sure javascript fires when document ready , not b4 that.
Comments
Post a Comment