RadAjax for ASP.NET AJAX

RadControls for ASP.NET AJAX

RadCodeBlock and RadScriptBlock are used to allow server and client script to work well together with AJAX updates.

RadCodeBlock

RadCodeBlock should be used when you have server code blocks placed within the markup (most often some JavaScript functions accessing server controls). RadCodeBlock prevents the server error:

System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

For more background on this issue see Understanding how <% %>expressions render and why Controls.Add() doesn't work.

The way code blocks (server script within "<%= %>" tags) are implemented in ASP.NET may interfere with the RadAjaxManager render interception mechanism. RadCodeBlock is used to isolate the code block preventing the error from appearing.

CopyASPX
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function AjaxReq(args) {
            $find("<%= RadAjaxPanel1.ClientID %>").ajaxRequestWithTarget("<%= Button1.UniqueID %>", '');
        }
    </script>
</telerik:RadCodeBlock>

RadScriptBlock

RadScriptBlock is used where you have JavaScript that evaluates after an AJAX request, for example when the content of RadAjaxPanel is updated asynchronously. RadScriptBlock also can be used like RadCodeBlock to handle server code blocks (<% ... %>).

RadScriptBlock wraps JavaScript where the JavaScript is located in an updating area. The example below shows a RadScriptBlock within a RadAjaxPanel.

CopyASPX
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
    <asp:Panel ID="Panel1" runat="server">
        <asp:Button ID="Button1" runat="server" />
        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
            <script type="text/javascript">
                alert(1);            
            </script>
        </telerik:RadScriptBlock>
    </asp:Panel>
</telerik:RadAjaxPanel>