Pass data from the JavaScript Object to the ASP.NET Ajax Enabled Server Control code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #1

    Pass data from the JavaScript Object to the ASP.NET Ajax Enabled Server Control code

    I've created a few ASP.NET Ajax Enable Server controls.

    There are 2 components to these controls: a server side Object that deals with the server side stuffs, and a client side Object that deals with the client side stuff.

    My controls are pretty nifty and quite useful but I keep coming back come back to the same question:

    How do I pass data from the JavaScript Object to the Server code?

    Up 'til now I've been using HiddenFields in order to accomplish my needs but I find this cumbersome, bulky, rather nasty looking and feeling...there has to be a better way!

    ASP.NET is smart enough to take the data from the server code and pass it into the JavaScript Object when it is loaded in the browser.

    Why can't it take the data from the client code (the JavaScript Object) and pass it into the Server Object when it is loaded on the server?

    Does anyone know how to do this?

    Or even have an idea of what I should be googling for because everything I find on these controls doesn't cover how to pass information from the JavaScript Object to the Server Object (they're usually very basic, simple articles/tutorials and I'm starting to wonder if anyone's even attempted to do this)

    I'm starting to look into JSON but I have no idea how I'm going to send the JSON Object to the server...or how to retrieve and this Object once it gets there...

    Thanks,

    -Frinny
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by Frinavale
    How do I pass data from the JavaScript Object to the Server code?
    the magic word is "serialization" . (I know of JSON and WDDX, but there may be more)

    Originally posted by Frinavale
    Why can't it take the data from the client code (the JavaScript Object) and pass it into the Server Object when it is loaded on the server?
    my guess is that this was not intended from the beginning. (despite that you need a new request for that)

    Originally posted by Frinavale
    I'm starting to look into JSON but I have no idea how I'm going to send the JSON Object to the server...or how to retrieve and this Object once it gets there...
    the crucial point is that you need a new http request for that (be it AJAX or a (re)load). which way to go probably depends on what that JS object is supposed to do in ASP.NET
    Last edited by Dormilich; Oct 26 '10, 05:12 AM.

    Comment

    • Eran Hefer

      #3
      Hi,
      I guess you found a solution already but for those of you who still having problems sending data from the client to the server: you can use ASP.NET Ajax and pass a JavaScript object to the server

      Check this post: http://ajaxme.blogspot.com/2010/10/p...to-server.html

      Eran Hefer.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        It's been a while since I've worked with any Server controls, and even though your post isn't related to server controls, it was insightful (a good refresher). It may have helped your blog if you explained what PageMethods is.

        The Extreme ASP.NET:Client-Side Web Service Calls with AJAX Extensions article explains the topic quite thoroughly.

        I am not prepared to expose any web methods in the project that I was working with...but this is a good idea for future projects. So long as the proper security is implemented around the web-methods to prevent unwanted execution from occurring.

        -Frinny
        Last edited by Frinavale; Oct 26 '10, 01:12 PM.

        Comment

        Working...