JavaScript functions calling C# functions and Viceversa
-
Hello there, I am developing an app that will have HTML/JS/CSS as the user interface component and then the back end will be C# that will be dynamically updating this web page. In order to do that i need the C# functions to be able to call JS functions in HTML page and the JS functions to be able to call C# functions. First of all, is this possible? If possible, how can i do that? Please guide me with sample code. Thanks in advance.
-
Hello there, I am developing an app that will have HTML/JS/CSS as the user interface component and then the back end will be C# that will be dynamically updating this web page. In order to do that i need the C# functions to be able to call JS functions in HTML page and the JS functions to be able to call C# functions. First of all, is this possible? If possible, how can i do that? Please guide me with sample code. Thanks in advance.
Well, first of all, you cannot get a server to push to a client over HTTP. It's a request/response protocol only. The reason for this is quite simple. The server has no idea if the client is still on the same page expecting data. The web server NEVER calls the client. Typically, the client will "refresh" a part of the page, such as data, by calling a method in your webserver to request new data over Ajax.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Well, first of all, you cannot get a server to push to a client over HTTP. It's a request/response protocol only. The reason for this is quite simple. The server has no idea if the client is still on the same page expecting data. The web server NEVER calls the client. Typically, the client will "refresh" a part of the page, such as data, by calling a method in your webserver to request new data over Ajax.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
First of all, forget about HTTP and all. I'm talking about a win forms app with a WinBrowser control embedded in it. No networks calls
You still can NOT do it. The two runtimes are completely separate and your only bridge between them is some kind of communication transport, such as Ajax. The JavaScript code is running inside the browser without any knowledge at all of anything outside of the sandbox it's running in in the browser.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Hello there, I am developing an app that will have HTML/JS/CSS as the user interface component and then the back end will be C# that will be dynamically updating this web page. In order to do that i need the C# functions to be able to call JS functions in HTML page and the JS functions to be able to call C# functions. First of all, is this possible? If possible, how can i do that? Please guide me with sample code. Thanks in advance.
Don Guy wrote:
First of all, is this possible?
As expressed - no. You have two applications. They need to communicate. So you will need a communications protocol that will run over a socket. How you do that depends on what exactly is running on the client and what exactly is running on the server. You might want to also insure that you really, really want to push to the client because that is very likely going to make things much more complicated. But if so then that is what you will be doing so you can google for that.
-
Hello there, I am developing an app that will have HTML/JS/CSS as the user interface component and then the back end will be C# that will be dynamically updating this web page. In order to do that i need the C# functions to be able to call JS functions in HTML page and the JS functions to be able to call C# functions. First of all, is this possible? If possible, how can i do that? Please guide me with sample code. Thanks in advance.
-
try this: functionName.OnClientClick = " return JavascriptSFunctionName()"; bofore this,you should make sure your JavascriptSfunction return true or false :)
Wrong, wrong, wrong. This is not calling a C# method from JavaScript, nor the other way around.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak