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

Page 1 of 3 123 LastLast
  1. #1

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

    Apologies if this is already implemented (couldn't see any examples).

    It would be useful to have the ability to define a JavaScript handler for things like "onBeforeAjaxRequest", "onAjaxRequestSucceeded", "onAjaxRequestFailed" etc on the ext ScriptManager.

    I see there are AjaxEvents for a given target or element, but I don't see how to set global handlers.


    Example of what I mean:

    <ext:ScriptManager
      runat="server"
      onBeforeAjaxRequest="My.ClientSideApi.GettingData"
      onAjaxRequestSucceeded="My.ClientSideApi.DataRetrieved"
      etc />
    For example, I have an application with a status bar. For every Coolite-based Ajax request, I'd like a global handler to fire before the ajax request is started so that I can add a little spinning icon in the status bar, and possibly some text, like "getting data..." etc. Then, when the request had eneded, I'd reset the status bar by calling a different JavaScript method.

    This way, each developer doesn't have to remember to call these things manually from their own controls.


  2. #2

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

    Hi Anup,

    We will be implementing something similar very shortly. It might be ready in the next couple days. I'll keep this thread updated with our progress.


    Geoffrey McGill
    Founder
  3. #3

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

    I think we're going to go with the following new Listeners on the <ext:ScriptManager>.

    Example

    <ext:ScriptManager runat="server">
        <Listeners>
            <AjaxRequestBefore ... />
            <AjaxRequestSuccess ... />
            <AjaxRequestFailure ... />
        </Listeners>
    </ext:ScriptManager>
    Because they're configured as <Listeners> you'll have access to all the standard Listeners properties such as Buffer, Delay, Fn, Handler, etc...

    Let me know if you have any feedback.

    Geoffrey McGill
    Founder
  4. #4

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

    This is great. Many thanks!
  5. #5

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

    Quick update...

    These new Listeners are being added, although we changed the names from what was posted above.

    Example

    <ext:ScriptManager runat="server">
        <Listeners>
            <BeforeAjaxRequest ... />
            <AjaxRequestComplete ... />
            <AjaxRequestException ... />
        </Listeners>
    </ext:ScriptManager>
    Geoffrey McGill
    Founder
  6. #6

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

    That's great -- the main thing is that it is in the Listeners for all the advantages you mention; far better than my original suggestion.

    Just one minor note: there's a typo in the second listener you had in the example.

    Look forward to seeing these changes. Is it for 0.9 (and if so, when is your ETA for 0.9)?

    Thanks for such a swift response.
  7. #7

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

    We've implemented the new ScriptManager Listeners.

    The following sample demonstrates all three listeners.

    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");
        }
    </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">
                <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">
                <AjaxEvents>
                    <Click OnEvent="Button1_Click" />
                </AjaxEvents>
            </ext:Button>
            
            <ext:Button ID="Button2" runat="server" Icon="Error" Text="Throw Exception">
                <AjaxEvents>
                    <Click OnEvent="Button2_Click" />
                </AjaxEvents>
            </ext:Button>
        </form>
    </body>
    </html>
    The new Listeners have been committed to SVN and will be publicly available with the next release. There is no firm date for the next public release.

    Hope this helps.

    Geoffrey McGill
    Founder
  8. #8

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

    This is awesome!


    Is it possible for the scriptmanager to fire off server side events too? I would like to run some server side logic on AjaxMethod error.
  9. #9

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

    Is it possible for the scriptmanager to fire off server side events too? I would like to run some server side logic on AjaxMethod error.
    Ya, we'll add them as AjaxEvents as well.


    You can also just use call an AjaxMethod inside the Listeners.


    The AjaxEvent versions should be committed later today.


    Thanks for the feedback.


    Geoffrey McGill
    Founder
  10. #10

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

    I meant actual regular server side events like Page.Load or Page.Error.
Page 1 of 3 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