beginner AJAX questions (AJAX.net)

Discussion in 'ASP .Net' started by darrel, Apr 27, 2006.

  1. darrel

    darrel Guest

    I've been playing with prototype.js and scriptaculous to create some nice
    drag-and-drop interaction on my applications GUI. That's working well.

    Now I want to take the next step and start passing data back and forth
    between my page and the server via AJAX.

    In terms of .net, can someone give me the overall concept?

    Normally, I'd have a function in my codebehind that grabs a dataset and then
    binds that to a control on my aspx page.

    Are there ajax libraries (1.1) that interact with that concept, basically
    'rebinding' a control over AJAX? Or is the concept more that I should have
    the server side code do the produce the HTML and then send that back?

    More specifically, I'm reading a bit of the ajax.net pro documentation:

    http://www.ajaxpro.info/Examples/DataSets/default.aspx

    where it talks about transferring datasets via the AJAX. I'm just not clear
    on how one would use that to, say, update a repeater control (since that it
    server-side concept, not client side).

    I'm not looking for specific code right now...just trying to wrap my head
    around the larger concept of what the server does vs. the GUI when trying to
    update data on screen via AJAX.

    Also, tangental question...does anyone know what the license for ajax.net
    pro is? I can't seem to find anything on the site. Is it open source?
    Commercial? Shareware?

    -Darrel


    --
    =================================================================
    Win prizes searching google:
    http://www.blingo.com/friends?ref=hM72-GU3FWzMFnTqhv-2GE1FNtA
     
    darrel, Apr 27, 2006
    #1
    1. Advertising

  2. darrel wrote:

    > Are there ajax libraries (1.1) that interact with that concept, basically
    > 'rebinding' a control over AJAX? Or is the concept more that I should have
    > the server side code do the produce the HTML and then send that back?
    >


    That's generally what I do for larger controls, but...

    > More specifically, I'm reading a bit of the ajax.net pro documentation:
    >
    > http://www.ajaxpro.info/Examples/DataSets/default.aspx
    >
    > where it talks about transferring datasets via the AJAX. I'm just not clear
    > on how one would use that to, say, update a repeater control (since that it
    > server-side concept, not client side).
    >


    You get back a dataset object serialized in JSON - you can use that to
    update your controls manually. I often do this for dropdowns etc.
    Return a List<T> serialized as JSON and use that to refresh my control
    with a for loop.

    Alternatively, you can pass a server control to your Ajax method,
    update it on the server, and plonk it back on the page, but I've not
    played with this and don't know how it handles Repeaters specifically.

    > I'm not looking for specific code right now...just trying to wrap my head
    > around the larger concept of what the server does vs. the GUI when trying to
    > update data on screen via AJAX.
    >


    The server is limited to returning data. Normally that'll be
    ready-to-eat HTML, some kind of Javascript object, or XML. The latter
    is falling out of favour these days, 'cos there's not much point to it
    unless you're talking to a webservice.

    What you do with the data on your side is up to you. Most frameworks
    hand-wave this a bit, and have various clever tricks to make Ajax fit
    into the Asp.Net model. Ajax pro doesn't - it sits outside the usual
    model and is faster and possibly more flexible for it, but you do have
    to go through a mental re-adjustment if you want to use it heavily. I'm
    currently using it quite a bit with the same libraries as you are, and
    it's a joy to behold - even if my script.aculo.us effects don't always
    work perfectly under IE.

    > Also, tangental question...does anyone know what the license for ajax.net
    > pro is? I can't seem to find anything on the site. Is it open source?
    > Commercial? Shareware?
    >
    > -Darrel
    >


    I think (don't quote me on this) it's a freebie to use, it's marked as
    beta so don't cry if it doesn't work. From what I can gather, Michael
    Schwarz is intending to produce a commercial version. It's largely
    closed source, but he does distribute the occasional code dump. If I
    really need to see what's happening, there's always Reflector.

    Your best bet is to hop over to the Ajax.Net user group @
    http://groups.google.co.uk/group/ajaxpro/ where the beautiful and
    talented Mr Schwarz will be happy to answer your questions.

    >
    > --
    > =================================================================
    > Win prizes searching google:
    > http://www.blingo.com/friends?ref=hM72-GU3FWzMFnTqhv-2GE1FNtA
     
    Flinky Wisty Pomm, Apr 27, 2006
    #2
    1. Advertising

  3. darrel

    darrel Guest

    Flinky:

    Wow. Lots of info! Thanks.

    So, it sounds like you use AJAX.net in the method I was thinking, where
    you'd return a chunk of HTML and then plop that back into the page via
    javascript (innerhtml or the like, I assume).

    That was my first inclination, but wanted to make sure I wasn't off base
    thinking like that.

    I often do that now just with standard codebehind, just because I like
    having that fine-level of control over my HTML, but I know it breaks the
    whole ideal of 'separate of data and presentation'.

    You also mentioned the 'passing the server control' method which sounds
    pretty slick, but I assume requires a much more integrated solution (ala
    atlas) to use?

    Again, thanks for the info!

    -Darrel
     
    darrel, Apr 27, 2006
    #3
  4. darrel

    MSDN Guest

    Flinky,

    What happens if you pass just the data and hydrating it into the HTML.
    Is this faster or just as you said send to the client html then plonk it.

    Also when you said you can pass JavaScript objects to the client. Is that
    correct or did I misunderstood you.

    if so how do you dish out JavaScript objects from the server side.

    can you serve any other objects to client and hydrate tags then?

    I am trying to use ATLAS and trying to understand the architecture at high
    level first then dig into details.

    Thanks...

    SA


    "Flinky Wisty Pomm" <> wrote in message
    news:...
    >
    > darrel wrote:
    >
    >> Are there ajax libraries (1.1) that interact with that concept, basically
    >> 'rebinding' a control over AJAX? Or is the concept more that I should
    >> have
    >> the server side code do the produce the HTML and then send that back?
    >>

    >
    > That's generally what I do for larger controls, but...
    >
    >> More specifically, I'm reading a bit of the ajax.net pro documentation:
    >>
    >> http://www.ajaxpro.info/Examples/DataSets/default.aspx
    >>
    >> where it talks about transferring datasets via the AJAX. I'm just not
    >> clear
    >> on how one would use that to, say, update a repeater control (since that
    >> it
    >> server-side concept, not client side).
    >>

    >
    > You get back a dataset object serialized in JSON - you can use that to
    > update your controls manually. I often do this for dropdowns etc.
    > Return a List<T> serialized as JSON and use that to refresh my control
    > with a for loop.
    >
    > Alternatively, you can pass a server control to your Ajax method,
    > update it on the server, and plonk it back on the page, but I've not
    > played with this and don't know how it handles Repeaters specifically.
    >
    >> I'm not looking for specific code right now...just trying to wrap my head
    >> around the larger concept of what the server does vs. the GUI when trying
    >> to
    >> update data on screen via AJAX.
    >>

    >
    > The server is limited to returning data. Normally that'll be
    > ready-to-eat HTML, some kind of Javascript object, or XML. The latter
    > is falling out of favour these days, 'cos there's not much point to it
    > unless you're talking to a webservice.
    >
    > What you do with the data on your side is up to you. Most frameworks
    > hand-wave this a bit, and have various clever tricks to make Ajax fit
    > into the Asp.Net model. Ajax pro doesn't - it sits outside the usual
    > model and is faster and possibly more flexible for it, but you do have
    > to go through a mental re-adjustment if you want to use it heavily. I'm
    > currently using it quite a bit with the same libraries as you are, and
    > it's a joy to behold - even if my script.aculo.us effects don't always
    > work perfectly under IE.
    >
    >> Also, tangental question...does anyone know what the license for ajax.net
    >> pro is? I can't seem to find anything on the site. Is it open source?
    >> Commercial? Shareware?
    >>
    >> -Darrel
    >>

    >
    > I think (don't quote me on this) it's a freebie to use, it's marked as
    > beta so don't cry if it doesn't work. From what I can gather, Michael
    > Schwarz is intending to produce a commercial version. It's largely
    > closed source, but he does distribute the occasional code dump. If I
    > really need to see what's happening, there's always Reflector.
    >
    > Your best bet is to hop over to the Ajax.Net user group @
    > http://groups.google.co.uk/group/ajaxpro/ where the beautiful and
    > talented Mr Schwarz will be happy to answer your questions.
    >
    >>
    >> --
    >> =================================================================
    >> Win prizes searching google:
    >> http://www.blingo.com/friends?ref=hM72-GU3FWzMFnTqhv-2GE1FNtA

    >
     
    MSDN, Apr 28, 2006
    #4
  5. Oooh! Two messages to reply to, sorry if this gets a bit intermingled.

    I can't give any info on ATLAS because I haven't touched it.

    My gut feeling is that hydrating controls from javascript objects will
    be slower than just chucking some HTML in place, but it gives you more
    control and has some merits of its own - I've got a dropdown list in a
    page, for example, which I populate from an array of JSON serialized
    objects.

    When the selectedIndex changes, I can look up the associated object and
    pass that object back to the server, complete with all its properties,
    making any changes I need to make before it goes. Pretty nice. I
    haven't tested the performance implications of either technique because
    the difference is likely to be minimal except for large controls. For
    big chunks, I think HTML will be faster. Consider it for tables, layout
    units etc. but being able to databind to objects which are valid on the
    server and client is a real breath of fresh air.

    Ajax pro supports the passing of server controls, but as I said, I
    haven't had a go yet. You can pass a control to the server, alter it,
    and pass it back to the client - I imagine that it's returned as HTML.
    Note that Ajax.Net does NOT play with ViewState. Most of the frameworks
    do, but take a performance/flexibility hit for sitting inside the
    ASP.Net model - this annoys me a bit, but I got over it. See: Mental
    re-adjustment. If you go all-out on Ajax.Net your pages end up _much_
    thinner on the server.

    Yes, SA you can pass Javascript objects to the client - Ajax.Net uses a
    serializer that takes an object like

    public class Foo
    {
    public string Bar
    {
    get{}
    set{}
    }
    }

    and returns a properties list string like {Bar:"value of Bar"}, Arrays
    are serialized in the same way so a List<Foo> would serialize as
    [{Bar:"somevalue"}, {"Bar:"Some other value"}, {Bar: "My third
    value"}].

    A deserializer on the server allows you to pass objects from the client
    to the server and persist them to DB/ make changes and return them.
    It's all quite neat.

    I keep meaning to build a new serializer built on generics which I
    think will be faster than the old object/casting one used in the
    framework as it stands, but... deadlines, you know?

    As to how you do it,

    public class MyPage{

    [AjaxPro.AjaxMethod]
    public Foo MyAjaxMethod(int someArg)
    {
    return new Foo(someArg.ToString());
    }
    }

    and in your javascript (the nasty way for brevity)

    var myReturnObject = MyPage.MyAjaxMethod(10);
    var myFoo = myReturnObject.value;
    doSomethingWithFoo(myFoo);

    HTH,

    -- flink
     
    Flinky Wisty Pomm, Apr 28, 2006
    #5
  6. Reading through that, it's a bit biased toward strings, you could
    equally do

    public class MyPage
    {
    [AjaxPro.AjaxMethod]
    public Foo MyOtherAjaxMethod(int someArg, DateTime someDate, Foo
    someFoo)
    {
    AlterFoo(ref someFoo, someArg, someDate);
    SaveFooToDb(someFoo);
    return someFoo;
    }
    }

    DateTimes and other basic types have their own serializers which make
    more or less sense depending on the version you're running.

    </flink>
     
    Flinky Wisty Pomm, Apr 28, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=

    No Class at ALL!!! beginner/beginner question

    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=, Feb 2, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    655
    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=
    Feb 3, 2005
  2. Richard Thornley

    Beginner ASP.Net questions

    Richard Thornley, Feb 9, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    428
    Kevin Spencer
    Feb 9, 2005
  3. Rensjuh
    Replies:
    7
    Views:
    1,042
    Mabden
    Sep 2, 2004
  4. =?Utf-8?B?SGFyZHkgV2FuZw==?=

    ASP.NET Ajax beginner question

    =?Utf-8?B?SGFyZHkgV2FuZw==?=, Jan 31, 2007, in forum: ASP .Net
    Replies:
    9
    Views:
    457
    Rob Meade
    Feb 2, 2007
  5. william nelson

    Beginner's Beginner

    william nelson, Apr 11, 2011, in forum: Ruby
    Replies:
    7
    Views:
    261
    7stud --
    Apr 12, 2011
Loading...

Share This Page