0

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

1 Answer 1

1

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();";
Sign up to request clarification or add additional context in comments.

2 Comments

thanks iv tried this but it doesnt work, doesnt flag any errors in console
What if you try saveSuccessScript = "test();";, then make the test be function test() { alert("ok"); }. Do you get the alert?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.