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

RadCodeBlock scripts not rendering on page when ajaxified parent control made visible=true

1 Answer 280 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
gunther
Top achievements
Rank 1
gunther asked on 23 Jun 2011, 03:29 PM
Long subject, I know, but here's what's happening:

I have a RadAjaxPanel.  Inside the RadAjaxPanel is an asp:Panel set to not visible and a button (button1).  Inside the asp:Panel is a button (button2) that calls a function called AlertIt() within a RadCodeBlock.  When button1 is clicked, it runs server code that makes the asp:Panel visible which, in turn, shows button2.  When you click button2, however, a Javascript error is thrown saying AlertIt() could not be found on the page.  button2 is showing like it should, so It's almost like it's stripping the Javascript out of the page.

When I remove the RadAjaxPanel so that the page does regular postbacks, it works just fine.  I've also tried a RadAjaxManager, but that yields the same results.

This is very urgent, so I hope someone can reply to this.  Here is all my code:

Master
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="TelerikIssues.Site1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server"></asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <asp:ValidationSummary runat="server" ID="ValidationSummary1" EnableClientScript="true"
            HeaderText="The following errors were encountered: " />
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

Content Page

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true"
    CodeBehind="disappearingjavascript.aspx.cs" Inherits="TelerikIssues.disappearingjavascript" %>
<%@ Register Src="~/controls/javascriptinclude.ascx" TagPrefix="uc" TagName="test" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
        <asp:Panel ID="pnlTest" Visible="false" runat="server">
            <asp:Button ID="Button1" Text="Alert It" OnClientClick="javascript:AlertIt();" runat="server" />
            <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                <script language="javascript" type="text/javascript">
                    function AlertIt() { alert("Success"); }
                </script>
            </telerik:RadCodeBlock>
        </asp:Panel>   
        <asp:Button ID="cmShow" Text="Show" OnClick="Show" runat="server" />
    </telerik:RadAjaxPanel>
</asp:Content>

1 Answer, 1 is accepted

Sort by
0
Genti
Telerik team
answered on 24 Jun 2011, 01:25 PM
Hi gunther,

What you are trying to accomplish is further explained in this post:
Insert Inline Javascript Inside Ajax Panel

Basically you need to intercept the asynchronous request, and then inject a script using the script manager instance.

Another solution would be to move the RadCodeBlock outside the the ajax panel, but I do not know if this would satisfy you as the script this time would be loaded on page load.

Hope this helps.

Kind regards,
Genti
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Ajax
Asked by
gunther
Top achievements
Rank 1
Answers by
Genti
Telerik team
Share this question
or