To paste a URL to ASPxHtmlEditor as a hyperlink, follow the steps below:
-
Subscribe to CommandExecuted and HtmlChanged events.
<dx:ASPxHtmlEditor ID="he" runat="server"> <ClientSideEvents HtmlChanged="he_OnHtmlChanged" CommandExecuted="he_OnCommandExecuted" /> </dx:ASPxHtmlEditor>
-
In the CommandExecuted event handler, check if the
PASTE
command is executed.function he_OnCommandExecuted(s, e) { if (e.commandName === ASPxClientCommandConsts.KBPASTE_COMMAND || e.commandName === ASPxClientCommandConsts.PASTE_COMMAND) process = 0; }
-
In the HtmlChanged event handler, obtain HTML code from the editor and replace each URL with the corresponding hyperlink in the HTML format.
function he_OnHtmlChanged(s, e) { if (process === 0) { process = -1; var text = s.GetHtml(); s.SetHtml(""); var newText = text.replace(/(?:(https?:\/\/[\/\w\.\,\-\?\=\&\%\+\#\&&]*[^<^<a\s^\)]\/?))(?=<br>|\ |<\/div>|$|\)|\s|\))/g, "<a href=\"$1\">$1</a>"); s.ExecuteCommand(ASPxClientCommandConsts.PASTEHTML_COMMAND, newText); } }
- Default.aspx (VB: Default.aspx)
(you will be redirected to DevExpress.com to submit your response)