0

My motto is to call a Java script function at the end of button click code behind. ie, firstly i need to execute the server side function after which my java script function should get invoked.

My server side method is as follows

protected string SaveEmbedURL_click()

{

    if (txtembedurl.Text != null)
    {
        School aschool = new School();
        aschool.SchoolId = CurrentSchool.SchoolId;
        aschool.EmbedUrl = txtembedurl.Text;
        SchoolRespository.updateEmbedUrl(aschool);
        return "true";
    }

}

My Java script function is as follows

function SaveEmbedUrlClientSide() {

admin_CustomizeTheme.SaveEmbedURL_click(true);
$('#lbl_embedcode').removeClass('hide').addClass('show');
$('#embedCode').removeClass('hide').addClass('show');
CopyToClipboard("embedCode");

}

How can i achieve this?

Thanks.

2 Answers 2

1

I'm pretty sure all you need is to add this

RegisterStartupScript("YourJavaScript", "SaveEmbedUrlClientSide()");

"YourJavaScript" is an arbitrary string that is used to identify the Javascript.

Here's the relevant MSDN article.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks conrad. But i think i am missing some parameter while using RegisterStartupScript. Can u explain how RegisterStartupScript should be used in my case?
RegisterStartupScript, which is Page.RegisterStartupScript is now obsolete so I wouldn't use this method anymore.
1

Page.RegisterStartupScript is now obsolete, so I would use this code.

ClientScript.RegisterStartupScript(Page.GetType, "Javascript", "SaveEmbedUrlClientSide();", true);

RegisterStartupScript requires Type, Reference, Code, render script blocks. Reference Here

Comments

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.