Skip to content

DevExpress-Examples/asp-net-web-forms-html-editor-paste-url-as-hyperlink

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTML Editor for ASP.NET Web Forms - How to paste a URL as a hyperlink

To paste a URL to ASPxHtmlEditor as a hyperlink, follow the steps below:

  1. Subscribe to CommandExecuted and HtmlChanged events.

    <dx:ASPxHtmlEditor ID="he" runat="server">
        <ClientSideEvents HtmlChanged="he_OnHtmlChanged" CommandExecuted="he_OnCommandExecuted" />
    </dx:ASPxHtmlEditor>
  2. 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;
    }
  3. 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\.\,\-\?\=\&\%\+\#\&&amp;]*[^&lt;^&lt;a\s^\)]\/?))(?=<br>|\&nbsp|<\/div>|$|\)|\s|\))/g, "<a href=\"$1\">$1</a>");
            s.ExecuteCommand(ASPxClientCommandConsts.PASTEHTML_COMMAND, newText);
       }
    }

Files to Review

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Paste a URL as a hyperlink in ASPxHtmlEditor

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •