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

RadGrid : Script controls may not be registered after PreRender.

3 Answers 276 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Maxime Bellemare
Top achievements
Rank 2
Maxime Bellemare asked on 08 Feb 2011, 09:40 PM
Hello,

Let me explain my situation I can not solve that contains a RadGrid.

In the name WebUserControl ListTable.ascx I put inside a RadGrid that lists my records and a select button and Delete.

Then I create a control named ViewModules.ascx.

Inside ViewModules.ascx I create dynamically in my div PlaceHolder and using a variable in my QueryString, add dynamically in my ListTable.ascx PlaceHolder.

I put in my Session variable control ListTable.ascx then replaced in the page when I press a Delete event of RadGrid is within ListTable.ascx.

You find my code below because I can not provide an example as it uses several library of our platform.

Have you any idea how to make my event the delete button or trigger and be able to see more control in my page?

You will find 3 screenshots that show you the steps to view my shares.

This error only happens with all Telerik controls. If I use Microsoft's control that we have by default with Visual Studio, my control works without error.

Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    If Me.IsPostBack AndAlso Not Session.Item("ViewModule") Is Nothing Then
        ModuleItemPlaceHolder.Controls.Add(DirectCast(Session.Item("ViewModule"), Control))
        Session.Remove("ViewModule")
    End If
End Sub
 
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        Dim site As CMS.Site.Item = CMS.Site.Provider.GetSite(Application)
        If Not site Is Nothing Then
            InitHeader(site)
            If Me.ModuleType = [Module].Enumeration.ModuleType.None Then
                ' Loading module icons
                ViewIcons(site)
            Else
                ' Loading module
                ViewModule(site)
            End If
        End If
    End If
End Sub
 
Private Sub ViewModule(ByVal site As CMS.Site.Item)
    Session.Remove("ViewModule")
    If Me.ModuleType = [Module].Enumeration.ModuleType.None Then
        Response.Redirect(String.Concat(site.Url, "/Gestion/"))
    Else
        Select Case True
            Case Me.ModuleType = [Module].Enumeration.ModuleType.News OrElse Me.ModuleType = [Module].Enumeration.ModuleType.SlideShows OrElse _
                 Me.ModuleType = [Module].Enumeration.ModuleType.Testimonials OrElse Me.ModuleType = [Module].Enumeration.ModuleType.User
 
                If Me.RecordID Is Nothing OrElse Not IsNumeric(Me.RecordID) Then
                    Dim ctrl As CMS.Controls.ListTable = DirectCast(LoadControl("~/CMSControls/Generic/ListTable.ascx"), CMS.Controls.ListTable)
                    ctrl.Module = Me.ModuleType
                    ctrl.EnableNewRecord = True
 
                    Dim handled As Boolean = False
                    RaiseEvent InitListTable(ctrl, handled)
 
                    Session.Add("ViewModule", ctrl)
                    ModuleItemPlaceHolder.Controls.Add(ctrl)
                Else
 
                End If
        End Select
    End If
End Sub

3 Answers, 1 is accepted

Sort by
0
Maxime Bellemare
Top achievements
Rank 2
answered on 09 Feb 2011, 05:25 PM
I found a post on the forums that you submitted with a sample "AJAXEnabledWebSite5.zip" at
http://www.telerik.com/community/forums/aspnet-ajax/grid/how-to-integrate-radgrid-into-a-customized-webcontrol.aspx

I added your class1.cs adding 2 GridButtonColumn (Select and Delete).

Then I actually added dynamically to the page Default.aspx the Grid control class.

I then put the control in the session and then add back in the Init and I have the same error.

0
Accepted
Veli
Telerik team
answered on 10 Feb 2011, 11:00 AM
Hi Claude,

You are saving your user control to the Session state after it has been added to the Controls collection of your page. On the next postback, you are getting the same control instance from the Session and adding it to the newly created Page instance (every postback creates a new Page instance). I do not believe this is a valid scenario. You need to save any data telling you what control exactly you need to recreate, and then you need to create a fresh instance of that control in the Init phase on postback. You should not be saving a Control in ViewState and then adding it to to the page on postback. Try saving the control name or path in the Session and then recreate the control on Init and see how this scenario works.

Greetings,
Veli
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Maxime Bellemare
Top achievements
Rank 2
answered on 10 Feb 2011, 03:07 PM
Thank you very much. The only solution to keep the name of the control and recreate the page in its Init function # 1.
Tags
Grid
Asked by
Maxime Bellemare
Top achievements
Rank 2
Answers by
Maxime Bellemare
Top achievements
Rank 2
Veli
Telerik team
Share this question
or