0

I have a javascript file to add product to database and I want to call it from class in backend. Is it possible? Btw: I found nothing about this

2 Answers 2

1

You can do this with

Page.ClientScript.RegisterStartupScript(this.GetType(),"CallMyFunction","MyFunction()",true);

MSDN Docs on the method

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

3 Comments

So, if I have js file sample.js, I need to replace CallMyFunction with its path?
No, you should not. You just need to refer sample.js on your aspx page.
@Eugene is correct (never noticed the comment from OP). Add the script file inside <script> tags on the aspx/cshtml file then it can be called with the above method from the code behind at any point.
1

If you have UpdatePanel on page then you can use below script

  ScriptManager.RegisterStartupScript(this, GetType(), "keyToRegister", "MyFunction();", true);

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.