views:

281

answers:

1

I have a SharePoint app that is configured correctly in the web.config for asp.net ajax, but when I try to use the Sys class it says it's undefined. I have installed SP2 and know that ajax is enabled because update panels work correctly. ScriptManager is being loaded to the page. I have a script link to register the external js file, and have confirmed that the url is correct. But I am using "_spBodyOnLoadFunctionNames.push(functionName())" to call the function that throws the error. Any help on this is greatly appreciated since all I come up with on google is how to integrate ajax into sharepoint.


JavaScript

_spBodyOnLoadFunctionNames.push(InitializeDynamicLoadingPanel());

function InitializeDynamicLoadingPanel() {
    modalLayerID = '';
    prm = Sys.WebForms.PageRequestManager.getInstance();
    IsAsyncPostBack = prm.get_isInAsyncPostBack();
    if (!IsAsyncPostBack) {
        prm.add_initializeRequest(InitializeRequestHandler);
        prm.add_beginRequest(BeginRequestHandler);
        prm.add_pageLoading(PageLoadingHandler);
        prm.add_pageLoaded(PageLoadedHandler);
        prm.add_endRequest(EndRequestHandler);
    }
}  


C#

ScriptLink.Register(page, "dynamicLoadingPanel.js", false);
A: 

Change the first line to:

_spBodyOnLoadFunctionNames.push("InitializeDynamicLoadingPanel");

Your current code is basically telling it to push the result of the InitializeDynamicLoadingPanel function, which is forcing the function to execute immediately, before the ScriptManager scripts have been embedded.

zincorp
@zincorp - Thanks for the reply. I tried that as well but it gave me an error in the init.js file. But I finally got it to work last night, and the issue was where I was calling _spBodyOnLoadFunctionNames. I have a js object named DynamicLoadingPanel and basically had the _spBodyOnLoadFunctionNames call inside the object which would be called during the object's initialization. So the fix was to call the _spBodyOnLoadFunctionNames.push("InitializeDynamicLoadingPanel()) with a Page.ClientScript.RegisterStartUpScript(). So you are correct with the embedded scripts statement. Thanks for the help.
jhorton