[CLOSED] AjaxEvent vs AjaxMethod

  1. #1

    [CLOSED] AjaxEvent vs AjaxMethod

    ToolbarButton
    1. Click Listener --> AjaxMethod
    2. Click AjaxEvent

    When is it better to use one over the other? Is it possible for buttons to share a listener or AjaxEvent? If I have 10 buttons, I want them to call the same serverside method and pass in the button's ID instead of creating 10 AjaxMethod/AjaxEvent. This is to minimize the amount of rendered scripts.
  2. #2

    RE: [CLOSED] AjaxEvent vs AjaxMethod

    Hi Jacky,

    Fundamentally there is very little difference between an AjaxEvent and AjaxMethod. An AjaxEvent is an AjaxMethod, but with a bit more configuration automatically handled for you.


    You could consider the AjaxMethod a slightly more manual way of making a server-side Method call than an AjaxEvent. An AjaxEvent will wrap up and hide much of the configuration and an AjaxEvent will generally require little, if not no, client-side configuration.


    If you're willing to muck around with a bit of JavaScript, there are options for sharing event wireup code and reducing the client-side footprint further than it already is. I'll have to create a sample.


    It's also not a problem to point all the Buttons OnEvent Handler to the same server-side Method.


    Hope this helps.


    Geoffrey McGill
    Founder
  3. #3

    RE: [CLOSED] AjaxEvent vs AjaxMethod

    Hi Jacky,

    Here's an option for reducing the client configuration script size. We set the .Handler property to a local JavaScript function, which calls an AjaxMethod.

    Example

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <script runat="server">
        [AjaxMethod]
        public void DoClick(string id)
        {
            Ext.Notification.Show(new Notification.Config
            {
                Title = "Message",
                Html = id + " was clicked!"
            });
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Coolite Toolkit Example</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager runat="server" AjaxMethodNamespace="CompanyX" />
        
            <script type="text/javascript">
                var doClick = function (el) {
                    CompanyX.DoClick(el.id);
                };
            </script>
            
            <ext:Button ID="Button1" runat="server" Text="Button 1" Handler="doClick" />
            <ext:Button ID="Button2" runat="server" Text="Button 2" Handler="doClick" />
            <ext:Button ID="Button3" runat="server" Text="Button 3" Handler="doClick" />
        </form>
    </body>
    </html>
    Hope this helps

    Geoffrey McGill
    Founder
  4. #4

    RE: [CLOSED] AjaxEvent vs AjaxMethod

    Cool! That's exactly what I am doing currently. I find assigning a handler leaves a much smaller footprint than attaching a listener. On complex pages, I only use AjaxMethods (shared if possible) instead of AjaxEvents. I also like being able to define the server side signature of AjaxMethods to pass parameters. Thanks for such a flexible framework!

Similar Threads

  1. [CLOSED] How to use AjaxMethod?
    By flormariafr in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 26, 2010, 7:03 PM
  2. Replies: 2
    Last Post: Jan 08, 2010, 2:47 AM
  3. [CLOSED] Load Coolite controls from AjaxEvent or AjaxMethod
    By pumpkin in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 02, 2009, 11:02 PM
  4. Different between AjaxEvent and AjaxMethod?
    By dbassett74 in forum 1.x Help
    Replies: 0
    Last Post: Apr 23, 2009, 10:17 PM
  5. A problem AjaxMethod and AjaxEvent
    By heysol in forum 1.x Help
    Replies: 2
    Last Post: Mar 23, 2009, 12:54 PM

Posting Permissions