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. How to call a C# Method from Javascript

How to call a C# Method from Javascript

Scheduled Pinned Locked Moved C#
tutorialcsharpjavascripthelp
5 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.
  • J Offline
    J Offline
    Jacobb Michael
    wrote on last edited by
    #1

    Hi all, How to call a C# method from a javascript. for example i am fetching a document.activeElement.value and i want to send this value to the C# method. Is it possible, if some one knows this pls help me thanks in adavance...

    D N A 3 Replies Last reply
    0
    • J Jacobb Michael

      Hi all, How to call a C# method from a javascript. for example i am fetching a document.activeElement.value and i want to send this value to the C# method. Is it possible, if some one knows this pls help me thanks in adavance...

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      You can have a hidden html control in your page and share the value through that between client and server side.

      It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

      1 Reply Last reply
      0
      • J Jacobb Michael

        Hi all, How to call a C# method from a javascript. for example i am fetching a document.activeElement.value and i want to send this value to the C# method. Is it possible, if some one knows this pls help me thanks in adavance...

        N Offline
        N Offline
        Nisha Agrawal
        wrote on last edited by
        #3

        you can share this value via hidden control as d@nish said else if you really want to call C# method from javascript then call it like this

        <%# serverMethod() %>

        1 Reply Last reply
        0
        • J Jacobb Michael

          Hi all, How to call a C# method from a javascript. for example i am fetching a document.activeElement.value and i want to send this value to the C# method. Is it possible, if some one knows this pls help me thanks in adavance...

          A Offline
          A Offline
          Anurag Gandhi
          wrote on last edited by
          #4

          You can easily call server side static method, pass some value to it and get the returned value on your page without page postback. You can write a static Method in your Code-File with:

          [System.Web.Services.WebMethod]
          public static string MyMethod(string value)
          {
          return SomeString;
          }

          Use Script Manager with PageMethods Enabled.

          Now you can call your server side method with:

          PageMethods.MyMethod(valueToPass, ChangeDDLValue, EnableDDL, dest);

          for details please go Google about Ajax PageMethods. Hope this will help

          Anurag Gandhi. http://www.gandhisoft.com Life is a computer program and every one is the programmer of his own life.

          J 1 Reply Last reply
          0
          • A Anurag Gandhi

            You can easily call server side static method, pass some value to it and get the returned value on your page without page postback. You can write a static Method in your Code-File with:

            [System.Web.Services.WebMethod]
            public static string MyMethod(string value)
            {
            return SomeString;
            }

            Use Script Manager with PageMethods Enabled.

            Now you can call your server side method with:

            PageMethods.MyMethod(valueToPass, ChangeDDLValue, EnableDDL, dest);

            for details please go Google about Ajax PageMethods. Hope this will help

            Anurag Gandhi. http://www.gandhisoft.com Life is a computer program and every one is the programmer of his own life.

            J Offline
            J Offline
            Jacobb Michael
            wrote on last edited by
            #5

            Hi Thanks a lot, I am using windows application which adds the scripts dynamically using BHO object and identifies the click even of the link.and actually i cant create the files in local disk from javascript(because of the security issues) so i thought of calling a c# method. then i realized that it cant be done.but we can call a webservice which can manipulate my data from javascript. Once again thanks for the solution.

            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