سؤال

I have seen several topics about execution of javascript code from codebehind (c#) (example).

Can anyone give the description of the process: how the client side code is run on the server side, what process does it go through? And what are it's pros and cons?

هل كانت مفيدة؟

المحلول

There is nothing like client side or server side. It is the environment where the code is being executed. In your server you have a container that is interpreting you C# code and compiling it to machine instructions. But in your web-browser there is some one to interpret your js code, that is know as javascript compiler like V8 in google chrome.

So if you have any C# sharp code that has some Javascript code too... Its C3 part will run in the server and output a code containing HTML, JS and CSS. So this is the servers output after applying the business logic.. the output code will run on Browser and since browser is intelligent enough to understand the HTML , Javascript code.

So this way your C# and Javascript code will execute.

نصائح أخرى

If it is client side code, it will not simply run on server there are situations where you want to add the client side code, from server side code so when the page loads from server, only then the client code can run e.g. try this in code behind: Response.Write("<script>alert('Hello');</script>"); in a button's click event, and put an HTML button on the form, call a javascript function from this HTML button that displays hello

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top