1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Script controls may not be registered before PreRender

Script controls may not be registered before PreRender

4 posts, 0 answered
  1. Hamza
    Hamza avatar
    8 posts
    Registered:
    20 May 2008
    03 Dec 2009
    Link to this post
    Hi,

    I am trying to upgrade from Sitefinity 3.2 to 3.7. I have a control for creating a comment on a blog post (which was working fine in 3.2) which is almost the same as CommentsList.acsx (control template). Earlier I was using a TextBox with ID "commentTxt" now it the 3.7 framework expect a RadEditor control. I tried replacing the TextBox with RadEditor then it asked me to put ScriptManager. When I placed ScriptManager on the control it started showing this message.

    Script controls may not be registered before PreRender.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidOperationException: Script controls may not be registered before PreRender.


    It seems as if I need to add the ScriptManager dynamically on the Page not on the control itself as it can only be done on PreInit event. Since the Blog details page is dynamically generated I couldn't find a way to add ScriptManager on the page. Though I tried this on the control's PreRender event:

    HtmlForm form1 = (HtmlForm)this.Parent.Parent.Parent.Parent;
    ScriptManager temp = new ScriptManager( );
    temp.EnablePageMethods = true;
    form1.Controls.AddAt(0, temp); 

    But it gives me this error:

    The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.


    Could you please suggest how can I solve this issue. Ideally if I could use a TextBox instead of RadEditor, but in case if RadEditor needs to be used then kindly point me to the correct direction.

    Regards,
    Hamza
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    03 Dec 2009
    Link to this post
    Hi Hamza,

    The ScriptManager issue is not related to Sitefinity. This is an ASP.NET AJAX topic. There are several ways you can go about this. The first and the quickest one would be to add a ScriptManager control in the markup of either the master page that you are using, or in the markup of the control itself. Note that you can have only one ScriptManager on a page, this means that if you add one on the masterpage:
    <telerik:RadScriptManager ID="sm" runat="server" >
    </telerik:RadScriptManager>

    you can not add any other script managers in controls that would be placed on pages that use this master page.

    Regards,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Hamza
    Hamza avatar
    8 posts
    Registered:
    20 May 2008
    06 Dec 2009
    Link to this post
    Hi Radoslav,

    Thanks for the solution.

    This did indeed solve the problem. However, the styles in my application are messing up the look of the RADEditor and it will take me an insane amount of time trying to fix that. Is there any way to just use a plain old textarea instead of the RADEditor?

    Regards,
    Hamza
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    06 Dec 2009
    Link to this post
    Hello Hamza,

    It is possible to replace the RadEditor with Textbox. You need to create a custom class that inherits from CommentsList and make the RadEditor control not required.

    protected override Telerik.Web.UI.RadEditor CommentText
        get 
        
            return base.Container.GetControl<RadEditor>("commentTxt", false); 
        

    I showed similar implementation here.

    Then you need to override InitializeControls, subscribe for SubmitButton.Command and set comment.Text = this.TextBox.Content; Another and easy option is removing all tools from the ToolsFile that RadEditor control uses. The tools file is located under ~/Sitefinity/ControlTemplates/Blogs/ToolsFile.xml.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 0 answered