Server-Side equivalent of pasteHtml?

Last post 02-04-2011, 12:43 PM by Adam. 3 replies.
Sort Posts: Previous Next
  •  02-01-2011, 8:22 PM 66002

    Server-Side equivalent of pasteHtml?

    Is there any way to 'paste html' into the current location of an editor using standard c# code instead of javascript? 
     
    For example, if I wanted to add the bold words "hello word" wherever the  cursor was last positioned when I clicked an .Net button, there would be code like:
     
    editor1.PasteHtml("<b>Hello World</b>");
     
    or, if we could get the last cursor position using a Property like "LastCursorPosition", we could manually do it ourselves:
     
    editor1.Text = editor1.Text.SubString(0,  editor1.LastCursorPosition) + "<b>Hello World</b>" + editor1.Text.SubString(editor1.LastCursortPosition); 
     
    --------------------
     I have tried PasteHTML within Javascript but running to problems for some reason. I looked at all your demos but it's just not working for me. Not sure if it has to do with the editor being inside an Ajax Update panel or something of the fact that I need to call RegisterStartUpScript because it's done on a postback? Anyway, if I could do it via server code, that would solve all my problems. 
  •  02-02-2011, 5:00 PM 66024 in reply to 66002

    Re: Server-Side equivalent of pasteHtml?

    sincell,
     
    It's possible.
     
    Please check the following example:
     
     
    The source code of this example is available in the download package.

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  02-04-2011, 11:15 AM 66059 in reply to 66024

    Re: Server-Side equivalent of pasteHtml?

    I already have a .Net button up and working like the example you pointed to.
     
    The problem is, just like in that example, the text"Hello Clicked" text is always appended to the end of the editor text.
     
    I would like to be able to click a server-side button and insert text at the current caret position of the editor.  (or whatever position it was at before it lost focus to click the server-side control). 
     
     Is that possible?
  •  02-04-2011, 12:43 PM 66062 in reply to 66059

    Re: Server-Side equivalent of pasteHtml?

    sincell,
     
    For this requirement, you need to use the client side JavaScript instead of server side function. To get the caret location you need to work with selection to get it. To get the selection you can use document. Selection. In Cute Editor, we provide the following API.
     
    editor.GetSelection=GetSelection;
     
    Then a range from the selection can be taken by the selection object's createRange. This gives the range. Once the range is available the rest is simple calculations only. This script can be moved to a Javascript file for using in different places.
     
    For your convenience, you should use Cute Editor API.
     
    PasteHTML()

    This method is used for pasting the specified HTML into a range within an editor document. If anything is selected, the selection is replaced with the new HTML and text.

    Example:

    // get the cute editor instance
    var editor1 = document.getElementById('<% = Editor1.ClientID%>');

    // pasting the specified HTML into a range within a editor document
    editor1.PasteHTML("Hello World");

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

View as RSS news feed in XML