RTE Dialogs Fail in .ascx User Control

Last post 05-19-2014, 6:09 AM by Kenneth. 3 replies.
Sort Posts: Previous Next
  •  04-23-2014, 10:46 AM 80262

    RTE Dialogs Fail in .ascx User Control

    I have implemented RTE in a few ASP.NET Web sites with success. Each time I put RTE in a .aspx page. But when installed to an ASP.NET User Control (.ascx), RTE dialogs fail to load properly as you can see in this screen shot. A vague error message appears. Note, I took the exact same configuration that failed in the ascx user control and put it in a .aspx page and everything worked fine. Is there is some problem with RTE that prevents its dialogs from loading properly from a .ascx user control? Or is there some special configuration that is required? Thanks.

     
  •  04-24-2014, 8:41 AM 80267 in reply to 80262

    Re: RTE Dialogs Fail in .ascx User Control

    Hi jeff330ci,

     

    I just tried with user control, it works fine. I think it should be some coding issue on your page. Can you try the example below too? If the example below works for you too, then can you create an demo which can reproduce this issue and send it to [email protected]? So I can check it for you directly.

     

    User control code

     

    1. <%@ Control Language="C#" ClassName="WebUserControl" %>  
    2. <%@ Register TagPrefix="RTE" Namespace="RTE" Assembly="RichTextEditor" %>  
    3. <RTE:Editor runat="server" ID="Editor1" />  
     

    .aspx page code which use the user control above. 

     

    1. <%@ Page Language="c#" ValidateRequest="false" %>  
    2.   
    3. <%@ Register TagName="uceditor" TagPrefix="UC" Src="~/WebUserControl.ascx" %>  
    4.   
    5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    6. <html xmlns="http://www.w3.org/1999/xhtml">  
    7. <body>  
    8.     <form id="Form1" method="post" runat="server">  
    9.         <UC:uceditor ID="uc1" runat="server" />  
    10.     </form>  
    11. </body>  
    12. </html>  
     

    Regards,

     

    Ken 

  •  05-16-2014, 11:06 AM 80300 in reply to 80267

    Re: RTE Dialogs Fail in .ascx User Control

    What is different about my scenario is that I programmatically insert the user control .ascx into the host .aspx page at runtime, during the Page_Load() event of the host .aspx. Your sample (and successful) usage of an .ascx user control has the .ascx user control declared in the .aspx page markup.

     

    What is important about the difference between the two techniques is this: When you declare the .ascx user control in the .aspx markup (as you do), then when the user control is loaded by the ASP.NET runtime, all of the page request lifecycle events fire for the user control up and to the Page_Load() event of the host page. That is, all the page events (PreInit, Init, InitComplete, PreLoad, and finally Load) fire for the user control. BUT when the user control is programmatically inserted as I do, not all page lifecycle events fire. 

     

    I suspect there is something about RTE dialogs that require/assume one or more of those page event lifecycle to fire in the host page whenever the dialog is opened. But unfortunately when hosted in an ASCX that is programmatically inserted at runtime, those assumptions/requirements are not satisfied.

     

    My scenario is not necessarily unusual in that many content management systems programmatically insert pages that are created at runtime. In these scenarios, there is never an .aspx page in which to declare the .ascx user control. In these scenarios, pages never physically exist and are programmatically created at runtime by a custom HTTP handler.

     

    It would be good if RTE dialogs would function properly in these scenarios. Is it possible RTE already does work in these scenarios, and there is something I am not doing correctly or otherwise failing to do?

     

    - Jeff 

  •  05-19-2014, 6:09 AM 80302 in reply to 80300

    Re: RTE Dialogs Fail in .ascx User Control

     Hi,

     

    I have tried load the user control programmatically in event Page_Load, it works for me too. Below is the code what I am testing. Does this way work for you too?

     

     

    1. <%@ Page Language="c#" ValidateRequest="false" %>  
    2.   
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    4. <html xmlns="http://www.w3.org/1999/xhtml">  
    5.     <script runat="server">  
    6.         protected override void OnLoad(EventArgs e)  
    7.         {  
    8.             Control cc = this.LoadControl("~/WebUserControl.ascx");  
    9.             cc.ID = "editor1";  
    10.             panel1.Controls.Add(cc);  
    11.             base.OnLoad(e);  
    12.         }  
    13.     </script>  
    14. <body>  
    15.     <form id="Form1" method="post" runat="server">  
    16.         <asp:Panel ID="panel1" runat="server"></asp:Panel>  
    17.     </form>  
    18. </body>  
    19. </html>  

    Regards,

     

    Ken 

View as RSS news feed in XML