Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. JavaScript functions calling C# functions and Viceversa

JavaScript functions calling C# functions and Viceversa

Scheduled Pinned Locked Moved C#
javascriptquestioncsharphtmlcss
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Don Guy
    wrote on last edited by
    #1

    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.

    D J E 3 Replies Last reply
    0
    • D Don Guy

      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.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      D 1 Reply Last reply
      0
      • D 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

        D Offline
        D Offline
        Don Guy
        wrote on last edited by
        #3

        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

        D 1 Reply Last reply
        0
        • D Don Guy

          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

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • D Don Guy

            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.

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • D Don Guy

              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.

              E Offline
              E Offline
              Elaine00
              wrote on last edited by
              #6

              try this: functionName.OnClientClick = " return JavascriptSFunctionName()"; bofore this,you should make sure your JavascriptSfunction return true or false :)

              D 1 Reply Last reply
              0
              • E Elaine00

                try this: functionName.OnClientClick = " return JavascriptSFunctionName()"; bofore this,you should make sure your JavascriptSfunction return true or false :)

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups