DNN Forums

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

CKEditor - Set value inside Repeater_ItemDataBound

Sort:
You are not authorized to post a reply.





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">
        <ItemTemplate>
            <div><dnn:TextEditor ID="txtHeaderText" runat="server" /></div><br />
        </ItemTemplate>
    </asp:Repeater>

    .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





      Try adding:
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { }

      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





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

        Martin






        New Around Here





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






          Veteran Member





            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





              Thank you, Will. I've changed it to Summernote's TextEditor (https://summernote.org/). Now everything works fine.
              You are not authorized to post a reply.

              These Forums are dedicated to the discussion of DNN Platform.

              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