register script on AJAX postback

3 posts, 0 answers
  1. robertgalvinjr
    robertgalvinjr avatar
    36 posts
    Member since:
    Jun 2006

    Posted 30 Dec 2009 Link to this post

    On my .ASPX page I have:
    <head id="Head1" runat="server">     
        <title></title>     
        <script type="text/javascript" src="swfobject.js"></script>     
    </head>     
    <body>     
        <form id="form1" runat="server">     
        <div>     
                 
           <telerik:RadScriptManager ID="RadScriptManager1" runat="server">     
            </telerik:RadScriptManager>     
            <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server"  LoadingPanelID="RadAjaxLoadingPanel1">     
      <asp:ImageButton ID="btnPrev" runat="server" onclick="btnPrev_Click"  ImageUrl="images/btnPrev.png"/>  
    <asp:ImageButton ID="btnNext" runat="server" onclick="btnNext_Click" ImageUrl="images/btnNext.png"/></td>  
                          
                              
    <div id="flashContent">     
                                     
                                </div>     
      </telerik:RadAjaxPanel>     
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default">     
            </telerik:RadAjaxLoadingPanel>     
     

    When I click the IMageButtons I need the scriptmanager to execute a javascript function that is in the swfobject.js file. I can get this to happen on the Page_Load (below) but not on the button clicks. What do I need to do to fire off a javascript function on AJAX postbacks?

    sSWF += @"<script type=""text/javascript"">";  
            sSWF += @"var flashvars = false;";  
            sSWF += @"var params = { menu: ""false"", flashvars: ""FMSServerURL=" +  
                sServer + "&sID=" + sStreamID +  
                "&imgURL=" + imageURL + @""" };";  
            sSWF += @"   var attributes = { id: ""myDynamicContent"", name: ""myDynamicContent"" };";  
            sSWF += @"swfobject.embedSWF(""presoViewer.swf"", ""flashContent"", """ + swfWidth + @""", """ + swfHeight + @""", ""9.0.0"", """", flashvars, params, attributes);";  
            sSWF += "</script>";  
     
     
                    Type cstype = this.GetType();  
     
            ClientScriptManager cs = Page.ClientScript;  
     
              
                 cs.RegisterStartupScript(cstype, "SWFScript", sSWF, false);  
             
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 04 Jan 2010 Link to this post

    Hello robertgalvinjr,

    Please use the following code to register the script:

    RadAjaxPanel1.ResponseScripts.Add(sSWF)

    This should be enough to execute the script after the ajax request.

    Greetings,
    Veskoni
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Jeroen Speldekamp
    Jeroen Speldekamp avatar
    30 posts
    Member since:
    Mar 2005

    Posted 14 Jan 2010 Link to this post

    Try to do this in your page load function

    Remove this line
    ClientScriptManager cs = Page.ClientScript;

    Replace this line
    cs.RegisterStartupScript(cstype, "SWFScript", sSWF, false);

    by this
    RadScriptManager.RegisterStartupScript(this, this.GetType(), "SWFScript", sSWF, false);
Back to Top