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. Calling a ASP.NET C# function from javascript

Calling a ASP.NET C# function from javascript

Scheduled Pinned Locked Moved C#
csharpjavascripthtmlasp-netdatabase
3 Posts 3 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.
  • M Offline
    M Offline
    Matt Cavanagh
    wrote on last edited by
    #1

    Hi, im making a dynamic site in ASP.NET and coding in C#. And I have a problem. The system is kind of like a windows desktop where you can drag around windows etc etc, but now i want to run a function to add something to the database. And this is fine, using a asp button and using its onclick function. BUT that causes a postback which refreshes the windows back to their original places and resets everything back to how it started. So im thinking the best plan would be to just use an HTML button and run the C# function from JS. But I have no clue how to do that. Or even if thats what I should be doing. Thanks so much, Matt

    P N 2 Replies Last reply
    0
    • M Matt Cavanagh

      Hi, im making a dynamic site in ASP.NET and coding in C#. And I have a problem. The system is kind of like a windows desktop where you can drag around windows etc etc, but now i want to run a function to add something to the database. And this is fine, using a asp button and using its onclick function. BUT that causes a postback which refreshes the windows back to their original places and resets everything back to how it started. So im thinking the best plan would be to just use an HTML button and run the C# function from JS. But I have no clue how to do that. Or even if thats what I should be doing. Thanks so much, Matt

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      In order to do this without a postback you really want to consider using AJAX.

      1 Reply Last reply
      0
      • M Matt Cavanagh

        Hi, im making a dynamic site in ASP.NET and coding in C#. And I have a problem. The system is kind of like a windows desktop where you can drag around windows etc etc, but now i want to run a function to add something to the database. And this is fine, using a asp button and using its onclick function. BUT that causes a postback which refreshes the windows back to their original places and resets everything back to how it started. So im thinking the best plan would be to just use an HTML button and run the C# function from JS. But I have no clue how to do that. Or even if thats what I should be doing. Thanks so much, Matt

        N Offline
        N Offline
        nelo_
        wrote on last edited by
        #3

        You could probably implement the ICallbackEventHandler interface. The MSDN sample is clear enough. I tried it successfully last week. I used to write a simple page that generated random numbers on the server. I had a loop in javascript that would retrieve the latest number and update a label on the page on the client side. Here's a link to the MSDN article I used as a guide: Implementing Client Callbacks Programmatically Without Postbacks in ASP.NET Web Pages[^]

        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