views:

196

answers:

4

I'm trying to find a way to delay all code that takes place after I make a service call. The reason for this delay is that my service returns code necesarry for the following functions and the result I pass is to these following functions is undefined.

I have tried attaching the setTimeout() to the function that is called directly after the service call, but then it just skips the function I set the timeout on and jumps to the next function...My web method that I am calling is not that big and is not doing anything that is too intensive

public bool GetSpreadsheetStatusForAdmin(string cacId)
    {
        SpreadSheetStatus result = new SpreadSheetStatus();
        List<Data.Spreadsheet> spreadsheets = SpreadsheetManager.GetUserSpreadsheets(GetCurrent.Identity);
        if (spreadsheets.Count != 0)
        {
            foreach (Data.Spreadsheet spreadsheet in spreadsheets)
            {
                if (spreadsheet.Status == SpreadsheetStatus.Pending)
                {
                    return true;
                }
            }
        }
        return false;
    }

I had found the delay() and thought that might work, but I don't have jquery 1.4 and can't use it as of yet.

is there anything that can help..?

+3  A: 

Call the function as a callback of your service call. How are you calling your service?

s_hewitt
that could work... I'll try that
Avien
A: 

here is some of the code..

the GetCheckedOutFieldingsForUser is the service call I was referring to in my post. The two EditUser functions below are the functions I would like to delay.. if I put the delay on the setTimeout('$popup.load("Forms/EditUserForm.htm #EditUserForm", null, function() { EditUserLoaded(cacId, onSaveCallback); });', 1000); it skips to the EditUserLoaded, which doesnt give the proper results

function EditUser(id, onSaveCallback) { $("#EditUserPopup").remove(); var $popup = $("<div id='EditUserPopup'></div>"); $("body").append($popup); $popup.load("Forms/EditUserForm.htm #EditUserForm", null, function() { EditUserLoaded(cacId, onSaveCallback); }); }

function EditUserLoaded(id, onSaveCallback)

{ $("#EditUserCancelButton").click(function() { ShotdownEditUserForm() });

alert(isCheckedOut + "EditUserLoaded");
CallMfttService("ServiceLayer/UserManager.asmx/GetUser", "{id:'" + id + "'}", function(result)
{
    if (!userIsAdmin)
    {
        $("#EditUserForm input").attr("disabled", "disabled");
        $("#EditUserForm select").attr("disabled", "disabled");
        $('#EditUserFormHeader').text("View User");
        $("#EditUserCancelButton").text("Close");
        $("#EditUserSaveButton").hide();
    }
    else 
    {
        if (isCheckedOut == "True")
        {
            $("#EditUserOrganization").attr("disabled", "disabled");
        }

        $("#EditUserSaveButton").click(function() { SaveUser(id, onSaveCallback); }).removeAttr("disabled");
    }
Avien
I can't tell what you're trying to do. Please edit your original question deleting anything that isn't relevant and properly formatting the code.
s_hewitt
A: 

well.. i couldn't ever get the function to delay and I couldn't use the onCallback to call the functions I wanted to delay. So I ended up setting the value I wanted to get when I load the page. I'm setting the values on the rows instead.. it's not exactly what I wanted to do, but it works. My page does load a fraction of a second slower too..

Avien
A: 

After rereading my original post I see it looks confusing as hell... what I ended up doing was; creating a second method getUserRecords that got a 'flag', I call getUserRecords from my first, getUser method and return a new object type with the flag included in the new object.

Avien