Modify RadRichTextEditor Content Control Text Programically

1 Answer 126 Views
RichTextEditor
Ali
Top achievements
Rank 1
Ali asked on 06 Sep 2021, 02:32 PM

Hello

I want to be able to modify the text content of the control programmically at runtime. Below is the code I have tried :

 Placeholder does not change the content
 Dim content_controls As IEnumerable(Of SdtRangeStart) =
        Me.radRichTextEditor1.Document.GetAnnotationMarkersOfType(Of SdtRangeStart)()
        For Each item In content_controls
            'MsgBox("Type: {0} ID:{1}", item.SdtProperties.Type, item.SdtProperties.ID)
            'MsgBox("Type: {0} ID:{1}", item.SdtProperties.Type, item.SdtProperties.ID)

            If item.SdtProperties.Type = SdtType.Text Then

                Dim properties As TextProperties = TryCast(item.SdtProperties, TextProperties)
                If properties.Tag IsNot Nothing AndAlso properties.Tag.ToUpper = "SERIALNO" Then
                    properties.Placeholder.PlaceholderText = "DWF324434244242"
                    properties.Placeholder.ShowPlaceholder = True
                End If
            End If
        Next
Thank You

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 07 Sep 2021, 08:42 AM

Hello Ali,

If the content controls already have contend the place holder text would not be displayed. You can change the actual content with the following approach (you need to update the layout as well): 

Dim content_controls As IEnumerable(Of SdtRangeStart) = radRichTextEditor1.Document.GetAnnotationMarkersOfType(Of SdtRangeStart)().ToList()
For Each item In content_controls
	If item.SdtProperties.Type = SdtType.Text Then
		Dim span As Span = TryCast(item.NextSibling, Span)
		If span IsNot Nothing Then
			span.Text = "DWF324434244242"
		End If
	End If
Next item

radRichTextEditor1.UpdateEditorLayout()


Let me know if I can assist you further.

Regards,

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Ali
Top achievements
Rank 1
commented on 07 Sep 2021, 11:40 AM

Thank You.

Its working perfectly.

Ali
Top achievements
Rank 1
commented on 09 Sep 2021, 11:51 AM

Hello

I want to be able to bind the span or control to a datasource, kindly assist me with the below code or other alternative;


  span.BindProperty(propertyToBind, bindingSource_renamed.Current, sourceProperty, PropertyBindingOptions.TwoWay)

 

Thank You

Dimitar
Telerik team
commented on 13 Sep 2021, 12:15 PM

Hi Ali

This is not supported and is not recommended (elements instances can be cloned or recreated at some point). Could share more information about your scenario? Perhaps I can suggest an alternative solution. 

I am looking forward to your reply.

Tags
RichTextEditor
Asked by
Ali
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or