SharePoint 2007: Script controls may not be registered before prerender

I hit this kind of nasty problems many times before and now I decided to put a few lines in here (so if I really can’t remember a thing then I might find this page by using google ;). So here is the scenario: I have custom application page (aspx page) in SharePoint 2007 (samething with WSS 3.0 or MOSS), and I use 3rd party controls in that page (Telerik RadControls for ASP.NET AJAX, any versions this far). When page that has scriptmanager and those controls loads up, it gives following error: "Script controls may not be registered before prerender". Now this is not nice error (after 2 days of debugging and hair pulling). But here is the cure for this: double check every overridden functions in your code behind file. I had only one overriden function that did not have normal "base.onprerender(e);" line. Missing that little base.X call caused that error. Now I do hope that someone finds this info useful or next time when I am struggling with this problem I might at least find my blog ;).

Btw. This info is somewhere back in the Telerik site too, but can’t remember or find original source at the moment.


About Sakarih

I am SharePoint developer/architect from Finland and my blogposts are all about SharePoint 2007/2010/2013 stuff. There might be also something else posted.
This entry was posted in SharePoint. Bookmark the permalink.

4 Responses to SharePoint 2007: Script controls may not be registered before prerender

  1. Unknown says:

    I am facing the same problem… I tried following the instructions but was unable to suceed.I am trying to create a Provider web part (connected web part) which passes the institute name. Please find the code below…usingSystem; usingSystem.ComponentModel; usingSystem.Web.UI; usingMicrosoft.SharePoint.WebPartPages; usingSystem.Xml.Serialization; usingSystem.Web.UI.WebControls; usingSystem.Data; usingSystem.Security; usingMicrosoft.SharePoint.Utilities; usingMicrosoft.SharePoint.WebPartPages.Communication; usingSystem.Data.SqlClient; usingSystem.Web.Configuration; usingTelerik.Web.UI; namespaceBDLProvider {public class BDLEdittableDropdown : WebPart, IRowProvider {public event RowProviderInitEventHandler RowProviderInit; public event RowReadyEventHandler RowReady; private bool _connected = false; private string _registrationErrorMsg = "An error has occurred trying to register your connection interfaces."; private bool _registrationErrorOccurred = false; private string _notConnectedMsg = "NOT CONNECTED. To use this Web Part connect it to a Cell, Row or ParamsIn Consumer Web Part."; private string _connectedWebPartLabel = "Connected to Web Part"; RadAjaxManager ajaxManager; RadScriptManager scrptMgr = new RadScriptManager(); RadComboBox _dropDownVessel = new RadComboBox(); private Button _rowButton=new Button(); private bool _rowButtonClicked = true; private string[] _rowFieldNames; private string[] _rowFieldDisplayNames; DataTable dataTable = new DataTable(); public BDLEdittableDropdown() {try {}catch (Exception ex) {throw ex; }}public override void EnsureInterfaces() {try {RegisterInterface("MyRowProviderInterface", InterfaceTypes.IRowProvider, WebPart.UnlimitedConnections, ConnectionRunAt.Server, this, "", "Provide Row To", "Provides a row to a consumer Web Part.", true); }catch (SecurityException se) {_registrationErrorOccurred = true; }}public override ConnectionRunAt CanRunAt() {return ConnectionRunAt.Server; }public override void PartCommunicationConnect( string interfaceName, WebPart connectedPart, string connectedInterfaceName, ConnectionRunAt runAt) {if (interfaceName == "MyRowProviderInterface") {_connected = true; }}public override void PartCommunicationInit() {EnsureChildControls(); if (_connected) {if (RowProviderInit != null) {RowProviderInitEventArgs rowProviderInitEventArgs = new RowProviderInitEventArgs(); rowProviderInitEventArgs.FieldList = _rowFieldNames;rowProviderInitEventArgs.FieldDisplayList = _rowFieldDisplayNames;RowProviderInit(this, rowProviderInitEventArgs); }}} public override void PartCommunicationMain() { if (_connected) {if (RowReady != null) {RowReadyEventArgs rowReadyEventArgs = new RowReadyEventArgs(); string selectionStatus = ""; DataRow[] dr = new DataRow[1]; if(_rowButtonClicked) {dr[0] = ((DataTable)_dropDownVessel.DataSource).Rows[_dropDownVessel.SelectedIndex]; selectionStatus = "Standard"; }else {dr[0] = null; selectionStatus = "None"; }rowReadyEventArgs.Rows = dr;rowReadyEventArgs.SelectionStatus = selectionStatus;RowReady(this, rowReadyEventArgs); }}} public override InitEventArgs GetInitEventArgs(string interfaceName) { if (interfaceName == "MyRowProviderInterface") {EnsureChildControls(); RowProviderInitEventArgs rowProviderInitEventArgs = new RowProviderInitEventArgs(); rowProviderInitEventArgs.FieldList = _rowFieldNames;rowProviderInitEventArgs.FieldDisplayList = _rowFieldDisplayNames;return (rowProviderInitEventArgs); }else {return (null); }}protected override void RenderWebPart(HtmlTextWriter output) {if (_registrationErrorOccurred) {output.Write(_registrationErrorMsg);return; }EnsureChildControls();if (_connected) {output.RenderBeginTag(HtmlTextWriterTag.Br); output.RenderEndTag();scrptMgr.RenderControl(output);_dropDownVessel.RenderControl(output); _rowButton.RenderControl(output);output.RenderBeginTag(HtmlTextWriterTag.Br); output.RenderEndTag();output.Write(_connectedWebPartLabel + ": "); output.RenderBeginTag(HtmlTextWriterTag.I); output.RenderEndTag();}else {output.Write(_notConnectedMsg);}}protected override void CreateChildControls() {Controls.AddAt(0, scrptMgr);ajaxManager = new RadAjaxManager(); ajaxManager.ID = "RadAjaxManager1"; Controls.Add(ajaxManager);this.Page.Items.Add(typeof(RadAjaxManager), ajaxManager); DataRow row; string connStr = WebConfigurationManager.AppSettings["ConnectionString"]; SqlConnection conn = new SqlConnection(connStr); conn.Open();SqlDataAdapter adapter = new SqlDataAdapter("SELECT Name FROM Institute", conn); adapter.Fill(dataTable);conn.Close();row = dataTable.NewRow();row["VesselName"] = string.Empty; dataTable.Rows.InsertAt(row, 0); _dropDownVessel.ID = "dropDownVessel"; _dropDownVessel.DataTextField = "VesselName"; _dropDownVessel.DataValueField = "VesselName"; _dropDownVessel.DataSource = dataTable;_dropDownVessel.DataBind();//_dropDownVessel.MarkFirstMatch = true; Controls.AddAt(1, _dropDownVessel);_rowButton.ID = "RowButton"; _rowButton.Text = "Filter"; Controls.AddAt(2,_rowButton);_rowButtonClicked = true; _rowButton.Click += new EventHandler(RowButtonClicked); int columnCount = dataTable.Columns.Count; _rowFieldNames = new string[columnCount]; _rowFieldDisplayNames = new string[columnCount]; for (int i = 0; i < columnCount; i++) {_rowFieldNames[i] = dataTable.Columns[i].ColumnName;_rowFieldDisplayNames[i] = dataTable.Columns[i].Caption;}}private void RowButtonClicked(object sender, EventArgs e) {base.OnPreRender(e); _rowButtonClicked = true; }}}Please help…..

  2. Unknown says:

    Resolution….Add the script manager to control collection in OnInit methodprotected override void OnInit(EventArgs e) { base.OnInit(e); scrptMgr = (RadScriptManager)RadScriptManager.GetCurrent(this.Page);// ScriptManager.GetCurrent(this.Page); if (scrptMgr == null) { scrptMgr = new RadScriptManager(); scrptMgr.EnablePartialRendering = true; Page.ClientScript.RegisterStartupScript(typeof(BDLEdittableDropdown), this.ID, "_spOriginalFormAction = document.forms[0].action;_spSuppressFormOnSubmitWrapper=true;", true); if (this.Page.Form != null) { string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"]; if (!string.IsNullOrEmpty(formOnSubmitAtt) && formOnSubmitAtt == "return _spFormOnSubmitWrapper();") { this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();"; } Controls.AddAt(0, scrptMgr); } } }

  3. Senthil says:

    Great one, You saved me lots of Time by Sharing this info. Thanks Again.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s