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

Bug report - Script control may not be registered after PreRender

11 Answers 486 Views
Input
This is a migrated thread and some comments may be shown as answers.
Cristi71000
Top achievements
Rank 1
Cristi71000 asked on 22 Apr 2008, 06:29 AM

Hi,

These are issues that have been reported by others. I am raising them as a bug reports to be evaluated by Telerik staff. There are two issues reported here.

Scenario: simple app - a RadTreeView on the left, clicking on a node dynamically loads a bunch of RadControls on the right.

Issue 1: If the controls on the right are displayed for the first time (i.e. first click on the corresponding node), they are displayed just fine. However, the second time a user visits a node, the following error is shown: "Script control may not be registered after PreRender".

The stack trace is below. It is obvious from the highlighted lines what generates the problem and I don't have any control over it. Kindly suggest a workaround or issue a fix

[InvalidOperationException: Script controls may not be registered after PreRender.]
   System.Web.UI.ScriptControlManager.RegisterScriptControl(TScriptControl scriptControl) +269
   System.Web.UI.ScriptManager.RegisterScriptControl(TScriptControl scriptControl) +99
   Telerik.Web.UI.RadWebControl.RegisterScriptControl() +43
   Telerik.Web.UI.RadWebControl.OnPreRender(EventArgs e) +39

   Telerik.Web.UI.RadInputControl.OnPreRender(EventArgs e) +28
   System.Web.UI.Control.PreRenderRecursiveInternal() +86
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041

Issue 2: Same scenario. When doing an action that postbacks the page, the tree is reloaded/rerendered. When this happens, a javascript error occurs:

"Sys.InvalidOperationException: A control is already associated with the element.
Code 0."

This is a showstopper and as of yet I have no explanation for it.

Both problems didn't exist before moving to the new version of the controls.

Thanks,
Cristian

11 Answers, 1 is accepted

Sort by
0
Konstantin Petkov
Telerik team
answered on 22 Apr 2008, 06:39 AM
Hello Cristi71000,

Please, review this post by my colleague Erjan. He has explained the problem in details and linked a project with a general solution.

I hope that helps you resolve the problem.

Best wishes,
Konstantin Petkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Cristi71000
Top achievements
Rank 1
answered on 22 Apr 2008, 07:53 AM
Thanks for pointing to this, but I don't think it's related to my problem, although it's the same error message. I don't have an Event distribuitor and I don't really want to implement one if at all possible. Is there another way around? I wouldn't expect this to resolve by actually adding an Event Distribuitor class...
0
Konstantin Petkov
Telerik team
answered on 22 Apr 2008, 10:09 AM
Hi Cristi71000,

Unfortunately I'm not sure what is causing the error in your scenario. Can you please share how do you load the user controls? I suppose the error may be thrown because of too late user control loading, but we will definitely need something to debug to be able to isolate the source of the problem.

Can you assemble a working subset of you project which replicates that? You can send it through regular support ticket. Looking forward to hearing from you.

Sincerely yours,
Konstantin Petkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Cristi71000
Top achievements
Rank 1
answered on 22 Apr 2008, 10:24 AM
Hi,

I will try to describe the code, because I have a very big solution with about 30+ projects in it and debugging on the whole thing is not an option.

Each node in my treeview is linked to an in memory object. If the object is not in memory it is loaded from the database. When the object loads, it loads some attributes which when the node is selected have to be displayed in the right-hand side of the page. Each of these attributes has a control (telerik or otherwise).
These controls are created at the time the attribute is loaded and will be displayed based on what the attribute contains. Thus whenever and attribute has to be shown, the right control is retrieved and added to the page. I can only do this operation in the PreRender stage, as I don't have all the required information before that. This works (and it worked so far with RadControls Q3 2008).
The first time one of these controls is displayed, all is ok. The second time the application crashes with the aforementioned message.

I managed to 'solve' the problem with a trick/workaround which I don't like. Every time I am displaying the control I create a new one to which I transfer all properties of the old one. I display the new control. Not sure if this will hold in the long run.

Any suggestions / fixes will be most welcome. I need to reinforce this project was working just fine on the previous release (non-prometheus).

Thanks,
Cristian
0
Konstantin Petkov
Telerik team
answered on 22 Apr 2008, 11:24 AM
Hi Cristi71000,

We believe the problem is indeed caused by keeping the object in memory. You should load/recreate the controls/objects each time in order to avoid any further problems like the ScriptManager errors because of the late script registration.

I'm afraid we can't suggest any other solution. Quite the opposite, we would strongly recommend you avoid the keeping-in-memory approach.

Greetings,
Konstantin Petkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Cristi71000
Top achievements
Rank 1
answered on 22 Apr 2008, 11:37 AM
Ok, I hope this will solve the problem - thanks for looking into it. However, I do have another one for you...

Same treeview. Clicking its nodes now displays the controls, reloaded as they are. On some postbacks however, I need to rebuild the tree. I clear the nodes, then rebuild them. However, the moment the page reloads after a rebuild, I get this JScript error which stops all js from working on the page:

"Sys.InvalidOperationException: A control is already associated with the element". The Tree is a control that is added at design time.

If I ignore the error and post the page back again I get: "Multiple controls with the same ID 'c9dc6c5c-f0e1-4cba-8187-e032563917e8' were found. FindControl requires that controls have unique IDs"

Any idea why this is? I definitely do not have duplicate IDs...

C
0
CSurieux
Top achievements
Rank 2
answered on 22 Apr 2008, 07:44 PM
Hello,

I must add that I have exactly the same 2 problems using a collection of controls created dynamically to enter portal/pages/modules settings, I have already open a previous thread on this.
I will try to extract a project presenting the dysfonction  but my main projet is also rather big.
I am very interested to know any progress on theses issues may be created by choice made in ajax.net architecture. All my code was running perfectly without Ajax.net AND is running when I replace the radTextBox by normal text box...

Regards
CS
0
Cristi71000
Top achievements
Rank 1
answered on 23 Apr 2008, 07:40 AM
Ok, found the problem with the second issue now - it was my fault, but the old RadTree wasn't generating the error. I had context menus on the tree. When on postback I was rebuilding the tree structure I was forgetting to clear the collection of ContextMenus before recreating them. Thus, on the first rebuild, all the ContextMenuItems were getting duplicated which resulted in an error when the $find JS function ran.
Clearing the Contextmenu collection of the RadTree solved this.
0
Veselin Vasilev
Telerik team
answered on 25 Apr 2008, 08:13 AM
Hi Cristi71000,

Can you please summarize what problem remains?

Also, I believe the best way to proceed is to isolate the problem in a small project and send it to us. So, we can test it locally and find where the problem is.

All the best,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Pedro
Top achievements
Rank 1
answered on 17 Sep 2008, 09:29 PM
I have a similar problem, I receive this error:

uncaught exception Sys.InvalidOperationException: Sys.InvalidOperationException: Type Telerik.Web.UI.RadInputControl has already been registered. The type may be defined multiple times or the script file that defines it may have already been loaded. A possible cause is a change of settings during a partial update

But this happens only on Safari (mac/windows) and Chrome.
IE and Firefox works fine.
The control that is causing the error is a RadDatePicker.

any clues?
0
smith spd
Top achievements
Rank 1
answered on 29 Jun 2010, 07:49 PM
Hello Cristi71000,

I am having the same issue and I m loading the RadTreeview by clearing the Contextmenus and nodes. But, I come across the same issue, Script Controls may not be registered after PreRender.
Any help will be appreciated.
Tags
Input
Asked by
Cristi71000
Top achievements
Rank 1
Answers by
Konstantin Petkov
Telerik team
Cristi71000
Top achievements
Rank 1
CSurieux
Top achievements
Rank 2
Veselin Vasilev
Telerik team
Pedro
Top achievements
Rank 1
smith spd
Top achievements
Rank 1
Share this question
or