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

Javascript in RadCodeBlock is not loaded

4 Answers 467 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Venkata Rajesh
Top achievements
Rank 1
Venkata Rajesh asked on 09 Jul 2012, 04:36 PM
Hi,

I have an aspx page that has a UserControl which is shown on a Button click in a RadWindow.

The usercontrol has javascript function's written in a RadCodeBlock that gets rendered when the aspx page loads. Now when i click the button to show the radWindow with userControl the javascript functions inside the RadCodeBlock of the userControl are not rendered.

I do know the work arounds of injecting the javascript from serverside but in terms of maintenance its a very big hassle as i would need to rebuild my entire project for a small javascript change. 

I tried moving the javascript functions to the aspx page but since they need the clientId of the controls inside the usercontrol its getting difficult to have them in the aspx page. 

How would i proceed?

Thanks in advance.

Rajesh

4 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 10 Jul 2012, 04:05 AM
Hi Venkata Rajesh,

Try replacing the RadCodeBlock with RadScriptBlock. You can find this article for more information on both controls. If the scripts are still missing when the user control is loaded, you will need to register them to the Page through the ScriptManager. You can do it on Page_Load of the UserControl for instance:

ScriptManager.RegisterStartupScript(Page, typeof(Page), "key", "alert('Am I registered?')", true);

In addition, you can use for a reference the below forum thread which discusses the same issue:
http://www.telerik.com/community/forums/aspnet-ajax/ajax/radajax-manager-does-not-load-js-files-in-dynamically-loaded-user-control.aspx

Regards,
Iana Tsolova
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Erik
Top achievements
Rank 2
answered on 11 Jul 2013, 06:25 AM
Hi Iana,

I did a replace from codeblock to scriptblock and it solved my problem. I've read the post you referred to (briefly...) but I am still wondering why the RadCodeBlock does not work?

Erik
0
Jonathan
Top achievements
Rank 2
answered on 19 Sep 2014, 04:08 AM
Hi Erik,

I had the same problem as yours and finally used RadScriptBlock for fix. Telerik said in their documentation to use RadCodeBlock if the script within contains $find('<%=whateverCtrl.ClientID%>'); something like that. I spent almost an hour solving this but it just not work with RadCodeBlock while my code inside the script has a validation of a RadGrid. RadCodeBlock is just lame when it included in a UserControl. Telerik needs to fix this.
0
Maria Ilieva
Telerik team
answered on 23 Sep 2014, 11:47 AM
Hi,

Note that RadCodeBlock and RadScriptBlock are used to allow server and client script to work well together with AJAX updates. RadCodeBlock should be used when you have server code blocks placed within the markup. RadScriptBlock is used where you have JavaScript that evaluates after an AJAX request.
Therefore in case you need to register a script form the UserControl you should use RadScriptBlock instead of a RadCodeBlock control.

Regards,
Maria Ilieva
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Ajax
Asked by
Venkata Rajesh
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Erik
Top achievements
Rank 2
Jonathan
Top achievements
Rank 2
Maria Ilieva
Telerik team
Share this question
or