[ADDED] [V0.8.1] Ability to define event handlers for all ajax requests in the ScriptManager

Page 2 of 3 FirstFirst 123 LastLast
  1. #11

    RE: [ADDED] [V0.8.1] Ability to define event handlers for all ajax requests in the ScriptManager

    Brilliant. Thanks. Looking forward to 0.9 :)
  2. #12

    RE: [ADDED] [V0.8.1] Ability to define event handlers for all ajax requests in the ScriptManager

    Any updates on firing off a server side event before the response is sent to client? I need to log each server side error that occurs. Thanks!
  3. #13

    RE: [ADDED] [V0.8.1] Ability to define event handlers for all ajax requests in the ScriptManager

    jchau (6/29/2009)Any updates on firing off a server side event before the response is sent to client? I need to log each server side error that occurs. Thanks!
    How about using an AjaxMethod?

    Geoffrey McGill
    Founder
  4. #14

    RE: [ADDED] [V0.8.1] Ability to define event handlers for all ajax requests in the ScriptManager

    Hmm...I am not sure if an AjaxMethod is the ideal solution here because I will be incurring an unnecessary server hit. It seems kind of silly for server to send error message to client, then client sent back exact error message to server. Ideally, I want to log the full detailed error on the server side and send back just a friendly error message to the client.

    The funny thing is that global error handling works fine for AjaxEvents. I am able to trap the error and send back a custom response and status code. It just wont work for AjaxMethods.
  5. #15

    RE: [ADDED] [V0.8.1] Ability to define event handlers for all ajax requests in the ScriptManager

    Hi,

    I just realized you have made these listeners available in 0.8.1, so I downloaded it and tried it out. Works great.

    Just one problem: it doesn't seem to work with AjaxMethods.

    E.g. in C# code-behind:

            [AjaxMethod]
            public static bool DoSomething()
            {
                return WasItDone();
            }
    And in ASP.NET:

            <ext:ToolbarButton ID="btnId" runat="server" Text="Test this">
                <Listeners>
                    <Click Handler="My.Code.DoSomething({
                        success : mySuccessHandler,
                        failure : myFailureHandler,
                        eventMask: { showMask: true, minDelay: 50, msg:'Getting...' }
                    });" />
                </Listeners>
            </ext:ToolbarButton>
    It may be my fault partly -- in the original request for this feature, I didn't clarify that I'd like it for AjaxMethods as well as Ajax Events.

    Is there a possibility of reusing the same listeners for either ajax call approach?
  6. #16

    RE: [ADDED] [V0.8.1] Ability to define event handlers for all ajax requests in the ScriptManager

    The events will be fired for all Ajax requests, including AjaxEvents and AjaxMethod calls.

    I added a couple AjaxMethod calls to the original sample.

    Example

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Button1_Click(object sender, AjaxEventArgs e)
        {
            Ext.Notification.Show(new Notification.Config
            {
                Title = "Button1_Click",
                AutoHide = false,
                Html = "Success!<br />" + DateTime.Now.ToString()
            });
        }
    
        protected void Button2_Click(object sender, AjaxEventArgs e)
        {
            throw new ArgumentException("Invalid Arguments");
        }
        
        [AjaxMethod]
        public void PopToast()
        {
            Ext.Notification.Show(new Notification.Config
            {
                Title = "AjaxMethod",
                AutoHide = false,
                Html = "Success!<br />" + DateTime.Now.ToString()
            });
        }
    
        [AjaxMethod]
        public void ThrowException()
        {
            throw new ArgumentException("Invalid Arguments");
        }
    </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 ID="ScriptManager1" runat="server" AjaxMethodNamespace="CompanyX">
                <Listeners>
                    <BeforeAjaxRequest Handler="popToast('BeforeAjaxRequest', el, action);" />
                    <AjaxRequestComplete Handler="popToast('AjaxRequestComplete', el, action);" />
                    <AjaxRequestException Handler="popToast('AjaxRequestException', el, action);" />
                </Listeners>
            </ext:ScriptManager>
    
            <script type="text/javascript">
                var popToast = function (title, el, action) {
                    Coolite.Ext.Notification.show({
                        title    : title,
                        autoHide : false, 
                        html     : String.format("control: {0}<br />action: {1}", el.id, action)
                    });
                };
            </script>
        
            <ext:Button ID="Button1" runat="server" Icon="Accept" Text="Before and Complete (AjaxEvent)">
                <AjaxEvents>
                    <Click OnEvent="Button1_Click" />
                </AjaxEvents>
            </ext:Button>
            
            <ext:Button ID="Button2" runat="server" Icon="Error" Text="Throw Exception (AjaxEvent)">
                <AjaxEvents>
                    <Click OnEvent="Button2_Click" />
                </AjaxEvents>
            </ext:Button>
            
            <hr />
            
            <ext:Button ID="Button3" runat="server" Icon="Accept" Text="Before and Complete (AjaxMethod)">
                <Listeners>
                    <Click Handler="CompanyX.PopToast();" />
                </Listeners>
            </ext:Button>
            
            <ext:Button ID="Button4" runat="server" Icon="Error" Text="Throw Exception (AjaxMethod)">
                <Listeners>
                    <Click Handler="CompanyX.ThrowException();" />
                </Listeners>
            </ext:Button>
        </form>
    </body>
    </html>
    Hope this helps.

    Geoffrey McGill
    Founder
  7. #17

    RE: [ADDED] [V0.8.1] Ability to define event handlers for all ajax requests in the ScriptManager

    Hi,

    Thanks for the extra example. It's weird. In my case I see AjaxRequestComplete and AjaxRequestException listeners fire for an AjaxMethod, but not BeforeAjaxRequest (and that's the one I need to set the status bar!).

    I tried your example locally and it works fine. I have tried to cut down my real solution but it is hard as there are lots of things in between (master templates, other JavaScript frameworks etc).

    It must be a problem on my end. So, at the moment while I can't provide a test case to help reproduce the problem I will work on it further...
  8. #18

    RE: [ADDED] [V0.8.1] Ability to define event handlers for all ajax requests in the ScriptManager

    Took a while but I finally figured out what was causing my problem:

    My AjaxMethod is declared as static. As soon as I take off static from my code it works.

    I used your example and making the AjaxMethod into a static method also fails your example (though in your case I don't get anything back to the client from the server, where as in my case I do -- it all runs except only BeforeAjaxRequest doesn't fire. I didn't look at that further -- there was an error in Firebug console, which probably explains that).

    So question is, should AjaxMethods not be static?
  9. #19

    RE: [ADDED] [V0.8.1] Ability to define event handlers for all ajax requests in the ScriptManager

    Hi,

    We have fixed it. The fix will be available in 0.8.2 release
  10. #20

    RE: [ADDED] [V0.8.1] Ability to define event handlers for all ajax requests in the ScriptManager

    Fantastic! Do you have a rough idea when 0.8.2 will be released?

    Thanks for your prompt responses. Really appreciated!
Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. [CLOSED] Event handler before direct event handlers
    By matejgolob in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jun 08, 2012, 2:31 PM
  2. Replies: 13
    Last Post: Jul 29, 2011, 4:24 AM
  3. Replies: 1
    Last Post: Mar 16, 2010, 3:58 PM
  4. Replies: 2
    Last Post: Jul 15, 2009, 2:07 PM
  5. [CLOSED] ScriptManager custom ajax event browser
    By methode in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Apr 14, 2009, 7:44 AM

Posting Permissions