John
John

Reputation: 3945

load js setTimeout from code behind

Using asp.net if I want to call a JS function from code behind I can use a ScriptManager...

string saveSuccessScript = "loadPopUp('Saved');";
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), key, saveSuccessScript, true);

But what if I want to call the setTimeout js function

setTimeout(function () {
            $("#saveDialogSingleFeature").dialog('close')
                    }, 3000);

which doesnt have a name. Ive given it one and tried to call it...

setTimeout(function timeO() {
        $("#saveDialogSingleFeature").dialog('close')
    }, 3000);

string saveSuccessScript = "timeO();";
    ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), key, saveSuccessScript, true);

this didnt work...any idea as to what I am doing wrong. ta

Upvotes: 0

Views: 996

Answers (1)

leopik
leopik

Reputation: 2351

I'm not sure how exactly asp.net processes this, but since you mentioned that you need to give the function some name, this could work.

function myTimeout() {
    setTimeout(function () {
        $("#saveDialogSingleFeature").dialog('close')
    }, 3000);
}

Then saveSuccessScript will be

string saveSuccessScript = "myTimeout();";

Upvotes: 1

Related Questions