Javascript in RadCodeBlock is not loaded

5 posts, 0 answers
  1. Venkata Rajesh
    Venkata Rajesh avatar
    8 posts
    Member since:
    Jul 2012

    Posted 09 Jul 2012 Link to this post


    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.

  2. Iana Tsolova
    Iana Tsolova avatar
    3388 posts

    Posted 09 Jul 2012 Link to this post

    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:

    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.
  3. DevCraft R3 2016 release webinar banner
  4. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 11 Jul 2013 Link to this post

    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?

  5. Jonathan
    Jonathan avatar
    3 posts
    Member since:
    Sep 2014

    Posted 18 Sep 2014 in reply to Erik Link to this post

    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.
  6. Maria Ilieva
    Maria Ilieva avatar
    4017 posts

    Posted 23 Sep 2014 Link to this post


    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.

    Maria Ilieva

    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.

Back to Top
DevCraft R3 2016 release webinar banner