3

How to call javascript function from server side

1
  • 1
    Please add some more detail to this question, I doubt whether it can be answered in this hazy state. Do you want to execute JavaScript code on server side? Or do you want to access a JavaScript function in the user's browser? Commented Jul 3, 2010 at 10:48

2 Answers 2

5

You can simply do a Response.Write("<script language='javascript'>nameOfJavascriptFunction();</script>"), or use ClientScriptManager.RegisterClientScriptBlock with a similar script.

The effect is that you are outputting a script tag calling your function - the call is still done on the client side.

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

2 Comments

Correct me if I'm wrong, but won't you get this error trying that code? Non-invocable member 'System.Web.HttpResponse.Output' cannot be used like a method. Also, wouldn't we need to escape those double-quotes in the 'language' attribute? Perhaps since you wrote this it has changed? This might be the way to go now: Response.Write("<script language=\"javascript\">nameOfJavascriptFunction();</script>"); @Oded - I'll vote up for the right answer, I just wanted to make sure it is current.
@Dylan-INNOSoftware - Naw, you got it right... Thanks - good catch :)
0

How about having the client side polling the server for actions instead? Do a call to the server side to check for a certain state, and if that state is fulfilled call the function? Should be easily achieved.

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.