Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
35
SharePoint 2007 Web Part: Error Script Controls may not be registered before PreRender
posted

I have an Infragistics grid working fine in a User Control ASCX file.  Now I am trying to load it into a web part.  Initially an error said "you need a script manager on the page".  So I added it during CreateChildControls:

 this.Controls.Clear()
 this.Controls.Add(new ScriptManager());
 userControl = (UserControl)this.Page.LoadControl
  (@"/_controltemplates/myUserControl/myListControl.ascx");
 this.Controls.Add(userControl);

Now I get the following error, which you may get if your OnPreRender methods do not call base.OnPreRrender.  I checked using reflector, and the Infragistics methods FlatDataBoundControl and WebDataGrid do indeed call base.OnPreRender.  These are the only PreRender events in the stack.  Note:  I do not override OnPreRender myself.

Any ideas?   Thanks!  Ed.

[InvalidOperationException: Script controls may not be registered before PreRender.] System.Web.UI.ScriptControlManager.RegisterScriptControl(TScriptControl scriptControl) +349529 System.Web.UI.ScriptManager.RegisterScriptControl(TScriptControl scriptControl) +66 Infragistics.Web.UI.Framework.Data.FlatDataBoundControl.OnPreRender(EventArgs e) +1111 Infragistics.Web.UI.GridControls.WebDataGrid.OnPreRender(EventArgs e) +5 System.Web.UI.Control.PreRenderRecursiveInternal() +80 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.WebControls.WebParts.WebPart.PreRenderRecursiveInternal() +42 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.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842

  • 395
    posted

    Hi,

    I ran into the same problem and trying to solve his in differernt ways, overriding PreRender, setting a ScriptManager in OnInit but nothing worked.

    The solution is to look at the AjaxSmartPart.cs from http://smartpart.codeplex.com/SourceControl/ListDownloadableCommits.aspx. I included the code from the OnInit method in the AjaxSmartPart.cs into the OnInit in the webpart that loads the user control. Now the ScriptManager is loaded correctly in our environment.

    Reagrds

  • 14049
    Offline posted
    Hi,
    I am guessing the grid was not able to register its javascript files
    early in the cycle since there was no ScriptManager available. Is it
    possible to add ScriptManager earlier?