Forums

Load JavaScript via a callback.

Last post 9/2/2008 4:05 AM by Anonymous. 6 replies.
Sort Posts: Previous Next
  • Thieme

    Load JavaScript via a callback.

    9/1/2008 4:09 PM
    • Not Ranked
    • Joined on 3/20/2008
    • Posts 6

    Hi,

    How can I load JavaScript via a callback?

    For example, I want to add a separated JavaScript file to UserControl1.ascx form this example: http://www.devexpress.com/Support/Center/e/E346.aspx

    So I changed UserControl1.asx to this:

     

     <%@ Control Language="C#" AutoEventWireup="true" CodeFile="UserControl1.ascx.cs" Inherits="ASPxperience_PopupControl_HowToLoadUserControlViaCallback_UserControl1" %>

     <%@ Register Assembly="DevExpress.Web.ASPxEditors.v8.1" Namespace="DevExpress.Web.ASPxEditors"

         TagPrefix="dxe" %>

    <script src="MyJavaScript.js" type="text/javascript"></script>

     <table cellpadding="0" cellspacing="0" style="width: 100%;">

         <tr>

             <td>

                 <dxe:ASPxLabel ID="ASPxLabel1" runat="server" Text="UserControl 1 has been loaded successfully">

                 </dxe:ASPxLabel>

             </td>

         </tr>

         <tr>

             <td style="padding-top: 10px;" align="center">

                 <dxe:ASPxButton ID="okButton1" runat="server" Text="Ok" AutoPostBack="false">

                     <ClientSideEvents Click="function(s, e) { MyJSFunction(); } "/>

                 </dxe:ASPxButton>

             </td>

         </tr>

     </table>

     

    MyJSFunction();  is added in MyJavaScript.js. But when I ran this, MyJSFunction(); can’t be found? Why is that?

    I hope you can explain this to me.

    Thanks,

    Thieme

    Filed under: ,
  • Gary L Cox Jr [DX-Squad]

    Re: Load JavaScript via a callback.

    9/1/2008 4:25 PM
    • Top 50 Contributor
    • Joined on 9/9/2007
    • Austin, Tx
    • Posts 811

    Thieme,

       You cannot load javascript from a callback.  This can only be registered on a Postback then called on the client side.

  • Thieme

    Re: Load JavaScript via a callback.

    9/1/2008 4:46 PM
    • Not Ranked
    • Joined on 3/20/2008
    • Posts 6

    Okay, thanks for reply.

    But when I load an ASPxGridView via a callback, I see variable WebResource.axd which consist of JavaScript code. I am wondering how they do that.

    Thanks,
    Thieme

  • Gary L Cox Jr [DX-Squad]

    Re: Load JavaScript via a callback.

    9/1/2008 6:47 PM
    • Top 50 Contributor
    • Joined on 9/9/2007
    • Austin, Tx
    • Posts 811

    ClientScript.RegisterClientScriptBlock(GetType(), "__MyScriptKey", "some javascript here", true);  If you add the script tag to your javascript, then set last param to false.  The last param adds that for you if set to true.  You can also register a javascript file.

  • Andrew R (Developer Express)

    Re: Load JavaScript via a callback.

    9/2/2008 2:37 AM
    Answer

    Hi!

    Included scripts, which are obtained from the server via a callback and then inserted into the page's HTML markup, aren't interpreted by the client browser, by default.
    If you call a function from such an included script, an exception is raised.
    We've found a workaround to this problem for our controls internally, by searching on the client side for included scripts with specific predefined IDs (which start from 'dxis_') and making them available to be executed by the browser.
    For example:

    <script src="MyJavaScript.js" type="text/javascript" id="dxis_MyScript"></script>

  • Thieme

    Re: Load JavaScript via a callback.

    9/2/2008 4:01 AM
    • Not Ranked
    • Joined on 3/20/2008
    • Posts 6

    Yes, thanks it works now!

    Thank you very much :)

  • Anonymous

    Re: Load JavaScript via a callback.

    9/2/2008 4:05 AM
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.