This is a migrated thread and some comments may be shown as answers.

Customise InsertHyperlinkDialog

1 Answer 47 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 07 Sep 2017, 11:27 PM

Hi

I'd like to customise the InsertHyperlinkDialog so that it only accepts links that start with http. Is there any way to do this?

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 08 Sep 2017, 08:15 AM
Hello Simon,

By default when the user presses the OK button the "http://" is inserted at the beginning of the link. However, you can insert it when the user starts typing in the text box. The following example shows how you can create custom dialog access the text box and change the text:
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
    public RadForm1()
    {
        InitializeComponent();
        radRichTextEditor1.RichTextBoxElement.InsertHyperlinkDialog = new MyInsertHyperlinkDialog();
    }
}
class MyInsertHyperlinkDialog : InsertHyperlinkDialog
{
    public MyInsertHyperlinkDialog()
    {
        var textbox = this.Controls[7] as RadTextBox;
        textbox.TextBoxElement.TextBoxItem.TextChanged += Textbox_TextChanged;
    }
 
    private void Textbox_TextChanged(object sender, EventArgs e)
    {
        var textbox = sender as RadTextBoxItem;
        if (!textbox.Text.Contains("http://"))
        {
            textbox.Text = "http://" + textbox.Text;
            textbox.SelectionStart = textbox.Text.Length;
        }
    }
}

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
RichTextEditor
Asked by
Simon
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or