Script controls may not be registered after PreRender.

12 posts, 0 answers
  1. Joe Joseph
    Joe Joseph avatar
    7 posts
    Member since:
    Jun 2009

    Posted 13 Sep 2010 Link to this post

    I am using Normal telerik radgrid bind.

    on OnLoad Event i called load grid functionality.

     

       
      
    private void OnLoad()
      
    {
      
    uxUserList.DataSource = Model.UsersModelList;
      
    uxUserList.DataBind();
      
      
    }

     

     

    it's working fine.

    but when i enabled AllowPaging="true" i get the following error.

    i am using RadScriptManager on My master page. and Perticular code block is
    called inside a user control.

     

     

     

     


     

    Server Error in '/Baker.IssueTrackingSystem.Web' Application.

    Script controls may not be registered after 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 after PreRender.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [InvalidOperationException: Script controls may not be registered after PreRender.]
       System.Web.UI.ScriptControlManager.RegisterScriptControl(TScriptControl scriptControl) +348527
       System.Web.UI.ScriptManager.RegisterScriptControl(TScriptControl scriptControl) +66
       Telerik.Web.UI.RadDataBoundControl.RegisterScriptControl() +43
       Telerik.Web.UI.RadDataBoundControl.ControlPreRender() +15
       Telerik.Web.UI.RadComboBox.OnPreRender(EventArgs e) +25
       System.Web.UI.Control.PreRenderRecursiveInternal() +80
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.AddedControl(Control control, Int32 index) +8682853
       System.Web.UI.ControlCollection.Add(Control child) +80
       Telerik.Web.UI.RadGrid.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +238
       System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
       System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
       System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
       System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
       System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
       Telerik.Web.UI.RadGrid.DataBind() +21
       System.Web.UI.Control.DataBindChildren() +211
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
       System.Web.UI.Control.DataBind() +15
       WebFormsMvp.Web.<>c__DisplayClassa`1.<Register>b__9(Object sender, EventArgs e) +15
       System.EventHandler.Invoke(Object sender, EventArgs e) +0
       System.Web.UI.Page.OnPreRenderComplete(EventArgs e) +8699938
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1029
    

     

     

     

     

     


     

     

  2. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 14 Sep 2010 Link to this post

    Hello Joe,

    Looking at the call stack you have pasted, it seems that you are using WebFormsMVP. Therefore, I suspect that the cause for the error you are getting is the way MvpUserControl is implemented. As you may know the class exposes an AutoDataBind property, which by default will cause a call to DataBind on PreRenderComplete event. However, this will eventually recreate all databound controls too late in the page's lifecycle causing IScriptControl implementers to thrown the mentioned exception. Thus, could you set AutoDataBind property to false (inside UserControl's constructor) and see if this makes any difference in the observed behavior.

    Greetings,
    Rosen
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rob
    Rob avatar
    4 posts
    Member since:
    Feb 2012

    Posted 15 Feb 2012 Link to this post

    Rosen, you are my hero!

    I am using MVP framework as explained on http://webformsmvp.com/ and tried to data bind a RadGrid (Q2.2011) and got the same 'script controls may not be registered before prerender' error as described by Joe Joseph.

    After creating a constructor for my code behind class and setting the boolean AutoDataBind to false I still got the same error.
    On the verge of pulling my hair out I noticed that the method Register<T> in the PageViewHost class was called not once (as I was expecting since there was only one UserControl in my project at that point) but twice.

    And then it dawned to me; the Page which was carying the UserControl was using the MvpPage implementation, functioning as a container and thus calling the Register<T> method (and data binding) all of it's child controls.

    Anyhow, Rosen, thank you once again for your help.

    Excellent support from Telerik!
  5. Goran Karabeg
    Goran Karabeg avatar
    3 posts
    Member since:
    Oct 2009

    Posted 21 Mar 2012 Link to this post

    And how did you fix the problem Rob?
    I have the same problem myself.
    Using MVP framework where one user control has another one inside and I get this same error.
    Hope this does not means that I have to combine user controls in one big pile of code :).
  6. Rob
    Rob avatar
    4 posts
    Member since:
    Feb 2012

    Posted 21 Mar 2012 Link to this post

    Hi Goran,

    No, you do not have to combine all your user controls in to one big pile of code. Fortunately :-)

    You will need to set the property AutoDataBind to false in both MvpUserControl.cs and MvpPage.cs. These two classes can be found (in the original project) in the WebFormsMvp project in the map Web.

    Hope this helps.
    If you have any more questions, feel free to ask!
  7. Goran Karabeg
    Goran Karabeg avatar
    3 posts
    Member since:
    Oct 2009

    Posted 21 Mar 2012 Link to this post

    Hi and thanks for quick response.

    Well I did what you said, and now I don't have telerik script error on prerender, but I nothing shows in my radgrid :(.

    My scenario is : one big Usercontrol with searchbox and textbox and 5 others usercontrols.
    Each of these controls has a presenter, model  and radgrid + mvp:PageDataSource.

    Is there any way to bind this thing manually, with having AutoDataBind=true?

    Thanx,
    -Goran
  8. Rob
    Rob avatar
    4 posts
    Member since:
    Feb 2012

    Posted 21 Mar 2012 Link to this post

    Hi Goran,

    Are you using the OnNeedDataSource event on your RadGrid?
    That should do the trick.

    If not, could you post you're code / project so I could take a closer look?
  9. Goran Karabeg
    Goran Karabeg avatar
    3 posts
    Member since:
    Oct 2009

    Posted 21 Mar 2012 Link to this post

    Hi Rob.

    I'v tried with OnNeedDataSource event and while it gets the data from model it does not react when I change the main model(which other model use as a parent container).
    There is not much code to post since I am getting data from a web service and use only one telerik databound control  and one datasource control in each user control.
    It works well with normal Mvp wiring, all events are firing properly with no need for code behind.

    I think that changing the RadGrid binding kind of breaks up the fine logic of MVP pattern.
    On the other hand, I have to use Radgrid because of UI complexity that I have to develop so I will have to bind this thing manually somehow.

    Thanks for the help.

    -Goran
  10. Gus
    Gus avatar
    2 posts
    Member since:
    Jul 2013

    Posted 08 Jul 2013 Link to this post

    So anybody was successful on getting rid of this error using WebFormsMVP? I have this error and tried everything mentioned here but no success.
  11. Rob
    Rob avatar
    4 posts
    Member since:
    Feb 2012

    Posted 09 Jul 2013 Link to this post

    Hey Gus,

    Yes, back then I was succesful in getting rid of this error. Could you show me what your setup and/or post some code?


    Kind regards,
    Rob
  12. Gus
    Gus avatar
    2 posts
    Member since:
    Jul 2013

    Posted 09 Jul 2013 Link to this post

    Hey Rob,

    Thanks for your quick response! I was able to figure it out as well by reading and reading and reading your postL

    'On the verge of pulling my hair out I noticed that the method Register<T> in the PageViewHost class was called not once (as I was expecting since there was only one UserControl in my project at that point) but twice.

    And then it dawned to me; the Page which was carying the UserControl was using the MvpPage implementation, functioning as a container and thus calling the Register<T> method (and data binding) all of it's child controls.'

    I turned off AutoDataBind on the right place and it's working now.

    Thanks again!

    Gus
  13. Ashraf
    Ashraf avatar
    1 posts
    Member since:
    Dec 2013

    Posted 11 Dec 2013 Link to this post

    Please call
    base.OnPreRender(e);wherever overrding method OnPreRender()
    protected override void OnPreRender(EventArgs e)
    		{
    			base.OnPreRender(e);
    ................................
    ................................
    }


Back to Top
UI for ASP.NET Ajax is Ready for VS 2017