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

On Load Rad Treeview in UserControl Used with Master page gives error.

3 Answers 133 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Aayam
Top achievements
Rank 1
Aayam asked on 12 Nov 2008, 11:48 AM

Hi,

I am sure many of us aware of  this error :

System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).    
at System.Web.UI.ControlCollection.Add(Control child)    
at Telerik.Web.SkinRegistrar.RegisterCssReference(Page _page, Control _control, String _url)

My case is i have a master page used as template.
Now there is another page that has an user control in it which has the rad treeview in it.
I am using the javascript for rad treeview with on load functionality using web service.

To narrow down the problem i have just added a rad treeview with rad script manager to the user control
This user control is placed in an aspx page which has a master page set for it.
now While trying to access this page i am getting the same error.
Can anyone help me in this respect.
I need it urgently.
Thanks for your help in advance.

Ragards,
Aayam Singh

3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 12 Nov 2008, 12:37 PM
Hi Aayam,

Please wrap your javascript code with RadScriptBlock and let us know if that helps.

Greetings,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Aayam
Top achievements
Rank 1
answered on 13 Nov 2008, 06:18 AM
Hi,

Thanks for reply.

I have tried encapsulating the javascript within RadScriptBlock as well as RadCodeBlock.
But both of them are not working and i am receiving the same error.
In my javacript i have used : "var tree = $find("<%= rtvBrands.ClientID %>");"   to get the all then nodes for my tree.
As i can see that article you pointed me was explaining this issue clearly.

To explain more i have a Rad Treeview on the page with RadScriptManager.
The first level nodes are only populated when page load for the first time.
Then on expanding any node web service is being used to fetch the child nodes.
The javascript are present on Check and toggle client events of Rad Treeview but they don't contain any sever tag as above.
One particular Javascript function that creates an XML Document with data regarding all the nodes in brand treeview.
For this function i need all the nodes available to us and read there check status, hence i have to use the above server <% %> block
to get hold of Rad Treeview.
But even after commenting this code in javascript my code breaks with same error.
I have also tried to pass hardcoded clientId from Rad Treeview and run it but same error.

I am not persisting the on load nodes of Rad Treeview and there is not post back for any of the nodes for radtreeview.
Is there any other way i can resolve this problem and avoid this error?
One more thing i have migrated my project from .Net 1.1 to .Net 3.5 and using all the updated libraries of latest version.

Regards,
Aayam Singh

0
Accepted
Atanas Korchev
Telerik team
answered on 13 Nov 2008, 04:08 PM
Hi Aayam,

You can also try moving your code block out of the head tag - inside the body tag for example. Also commenting server side expressions with JavaScript comments will not work. You should use the server-side comments syntax - <%-- something --%>

Regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
TreeView
Asked by
Aayam
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Aayam
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or