This is a migrated thread and some comments may be shown as answers.

[Solved] Script controls may not be registered before PreRender - For WebPart

0 Answers 172 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
osama
Top achievements
Rank 1
osama asked on 26 May 2009, 09:27 PM
Guys

I am trying to develop a webpart nd integrate it with my sharepoint page, the webpart will contain Rad tree view but everytime i try to ass any of RAD controls i keep getting the following error when i try to view it within my sharepoint page:
Script controls may not be registered before PreRender.

Troubleshoot issues with Windows SharePoint Services.

Please note I have Followed the instruction of integrating both Ajax and Rad controls into my site.


I replaced the RadScriptManager with ScriptManager -- NO LUCK
I tired to add the treeview directly to the control but no luck



I spent almost a week now trying to figure out wht is wrong but no luck, Please HELP
Please note i have tried the following:





Option Explicit On
Option Strict On

Imports System
Imports System.Runtime.InteropServices
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Serialization

Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.WebControls
Imports Microsoft.SharePoint.WebPartPages
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.VisualBasic
Imports Microsoft.Office.InfoPath.Server
Imports Microsoft.Office.InfoPath.Server.Controls
Imports Telerik.Web.UI

Namespace ProjectStructure2

    <Guid("f74a57f5-9ecc-4d2d-bd33-0ac4e271218e")> _
    Public Class ProjectStructure2
        Inherits Microsoft.SharePoint.WebPartPages.WebPart

        Public MyXmlFormView As New XmlFormView
        Public tvProjectStructurte As New TreeView
        Public SQLConnection As New System.Data.SqlClient.SqlConnection("server=KHATTABO; database=UserMosic") ' Store the connection string
        Dim Names, Values, NamesAndType As New ArrayList
        Dim labeld As New Label
        Dim labeld2 As New Label
        Dim labeld3 As New Label
        Dim URL As New Label
        Dim thisWeb As SPWeb = SPContext.Current.Web
        Dim docLibName As String = "Projects List"
        Public PorjectID As Integer
        Public LevelsCounter As Integer
        Dim ss As New Label
        Dim MainTable As New Table
        Private displayName As Label
        Private inputName As TextBox

        Dim sss As New Table
        Dim TestTable As New Table
        Dim label As New Label
        Dim panel As Panel = New Panel()

        Public Sub New()
        End Sub

        Protected Overrides Sub OnInit(ByVal e As EventArgs)
            MyBase.OnInit(e)


            EnsurePanelFix()


        End Sub

        Protected Overrides Sub OnLoad(ByVal e As EventArgs)
            MyBase.OnLoad(e)

   

            Dim panel As New Panel
            panel.ID = "Panel1"
            Me.Controls.Add(panel)

            Dim treeView As RadTreeView = New RadTreeView()
            treeView.ID = "RadTreeView1"
            treeView.Nodes.Add(New RadTreeNode("What's the time?"))


            panel.Controls.Add(treeView)
            label = New Label()
            label.Text = "Hello"
           
            panel.Controls.Add(label)


            Dim ajaxManager As RadAjaxManager = RadAjaxManager.GetCurrent(Me.Page)
            If ajaxManager Is Nothing Then
                ajaxManager = New RadAjaxManager()
                ajaxManager.ID = "RadAjaxManager1"
                Me.Controls.Add(ajaxManager)
                Me.Page.Items.Add(GetType(RadAjaxManager), ajaxManager)
            End If

            ajaxManager.AjaxSettings.AddAjaxSetting(treeView, panel)
        End Sub

        Private Sub treeView_NodeClick(ByVal sender As Object, ByVal e As RadTreeNodeEventArgs)
            label.Text = DateTime.Now.ToLongTimeString()
        End Sub

        Protected Overrides Sub CreateChildControls()
            MyBase.CreateChildControls()

 
        End Sub

        Private Sub EnsurePanelFix()

            Page.ClientScript.RegisterStartupScript(GetType(ProjectStructure2), Me.ID, "_spOriginalFormAction = document.forms[0].action;_spSuppressFormOnSubmitWrapper=true;", True)
            If Not Me.Page.Form Is Nothing Then
                Dim formOnSubmitAtt As String = Me.Page.Form.Attributes("onsubmit")
                If Not String.IsNullOrEmpty(formOnSubmitAtt) And formOnSubmitAtt = "return _spFormOnSubmitWrapper();" Then
                    Me.Page.Form.Attributes("onsubmit") = "_spFormOnSubmitWrapper();"
                End If
            End If


            Dim scriptManager As ScriptManager = scriptManager.GetCurrent(Me.Page)
            If scriptManager Is Nothing Then
                scriptManager = New RadScriptManager() '  Please Note I also tried to use scriptManager = New ScriptManager()
                scriptManager.EnablePartialRendering = True
         
                Me.Controls.AddAt(0, scriptManager)
           
            End If

        
         




        End Sub


        Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
            MyBase.OnPreRender(e)
            EnsureChildControls()

        End Sub


    End Class


End Namespace

No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
osama
Top achievements
Rank 1
Share this question
or