DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

CKEditor - Set value inside Repeater_ItemDataBound

 5 Replies
 2 Subscribed to this topic
 26 Subscribed to this forum
Sort:
Author
Messages
New Around Here
Posts: 19
New Around Here

Hi everyone

on DNN 9.12.0 I am using TextEditor (CKEditor) inside a Repeater. Inside Repeater_ItemDataBound I try to set a value to the TextEditor. The following error occurs: 'txtHeaderText.Text' threw an exception of type 'System.NullReferenceException'.

I am using the following:

.ascx
<%@ Register TagPrefix="dnn" TagName="TextEditor" Src="~/controls/TextEditor.ascx"%>
<asp:Repeater ID="rptHeaderFooterText" runat="server" OnItemCommand="HeaderFooterText_ItemCommand" OnItemDataBound="HeaderFooterText_ItemDataBound">
    
        

<dnn:TextEditor ID="txtHeaderText" runat="server" />


    

.ascx.cs
protected void HeaderFooterText_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    try
    {
        var txtHeaderText = e.Item.FindControl("txtHeaderText") as TextEditor;
        
        if (txtHeaderText != null)
        {
            txtHeaderText.Text = "some value";
        }
    }
    catch (Exception exc)
    {
        Exceptions.ProcessModuleLoadException(this, exc);
    }
}

Any suggestions? Thank you.

Martin

New Around Here
Posts: 8
New Around Here
Try adding:
[code] if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { }[/code]
The itemdatabound event does execute for the header, footer, and separators also. However, I am not sure if it does if they are not present.
New Around Here
Posts: 19
New Around Here

Unfortunately the same error message and Editor's content still empty

Martin

New Around Here
Posts: 19
New Around Here

BTW: Everything works fine as long as TextEditor is outside of a Repeater.

Senior Member
Posts: 1607
Senior Member
MVP
MVP
You're an MVP!
New Poster
New Poster
Congrats on posting!

I'm not sure the text editor is meant to be contained in a repeater like that.  It would need to have some updates applied to support it, I think.  Especially some event handling.  If you wish to have a text editor in a repeated like that, you may be better off using a purely client-side HTML editor.  :)

New Around Here
Posts: 19
New Around Here
Thank you, Will. I've changed it to Summernote's TextEditor (https://summernote.org/). Now everything works fine.

These Forums are for the discussion of the open source CMS DNN platform and ecosystem.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
  2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
  3. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  5. No Flaming or Trolling.
  6. No Profanity, Racism, or Prejudice.
  7. Site Moderators have the final word on approving / removing a thread or post or comment.
  8. English language posting only, please.

Would you like to help us?

Awesome! Simply post in the forums using the link below and we'll get you started.

Get Involved