Common ExtraParams for all DirectEvents

  1. #1

    Common ExtraParams for all DirectEvents

    Hi all!
    I have multiple buttons and comboboxes, which uses DirectEvents. All that events requires ExtraParams, and many of them are same. Is there way to avoid copy-paste of this params?
  2. #2
    Hi,

    I can suggest this way:

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Button1_Click(object sender, DirectEventArgs e)
        {
            string s = e.ExtraParams["param1"] + " " + e.ExtraParams["param2"] + " " + e.ExtraParams["param3"];
            X.Msg.Alert("Button1_Click", s).Show();
        }
    
        protected void Button2_Click(object sender, DirectEventArgs e)
        {
            string s = e.ExtraParams["param1"] + " " + e.ExtraParams["param2"] + " " + e.ExtraParams["param3"];
            X.Msg.Alert("Button1_Click", s).Show();
        }
    </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 runat="server">
        <title>Ext.Net Example</title>
    
        <script type="text/javascript">
            var setDefaultExtraParams = function (extraParams) {
                extraParams.param1 = "Param1";
                extraParams.param2 = "Param2";
            }
        </script>
    
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:Button runat="server" Text="Button1">
            <DirectEvents>
                <Click OnEvent="Button1_Click" Before="setDefaultExtraParams(extraParams);">
                    <ExtraParams>
                        <ext:Parameter Name="param3" Value="Button1" Mode="Value" />
                    </ExtraParams>
                </Click>
            </DirectEvents>
        </ext:Button>
        <ext:Button runat="server" Text="Button2">
            <DirectEvents>
                <Click OnEvent="Button2_Click" Before="setDefaultExtraParams(extraParams);">
                    <ExtraParams>
                        <ext:Parameter Name="param3" Value="Button2" Mode="Value" />
                    </ExtraParams>
                </Click>
            </DirectEvents>
        </ext:Button>
        </form>
    </body>
    </html>
  3. #3
    That's cool, thanks!
  4. #4
    How can I retrieve Ext.NET control name in setDefaultExtraParams function, like I did in ExtraParam Value: "#{cbGroup}.value"?
  5. #5
    Please wrap <scipt> in <ext:XScript> control and use #{} syntax.
  6. #6
    Thanks, it works.
  7. #7
    Also you can use the ResourceManager BeforeAjaxRequest listener. In this case you will avoid setting up a Before handler for each DirectEvent.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        protected void Button_Click(object sender, DirectEventArgs e)
        {
            string s = e.ExtraParams["param1"] + " " + e.ExtraParams["param2"] + " " + e.ExtraParams["param3"];
            X.Msg.Alert("Button_Click", s).Show();
        }
    </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 runat="server">
        <title>Ext.NET Example</title>
     
        <script type="text/javascript">
            var setDefaultExtraParams = function (extraParams) {
                extraParams.param1 = "Param1";
                extraParams.param2 = "Param2";
            };
        </script>
     
    </head>
    <body>
        <ext:ResourceManager runat="server">
            <Listeners>
                <BeforeAjaxRequest Handler="setDefaultExtraParams(extraParams);" />
            </Listeners>
        </ext:ResourceManager>
        <ext:Button runat="server" Text="Button 1">
            <DirectEvents>
                <Click OnEvent="Button_Click">
                    <ExtraParams>
                        <ext:Parameter Name="param3" Value="Button1" Mode="Value" />
                    </ExtraParams>
                </Click>
            </DirectEvents>
        </ext:Button>
        <ext:Button runat="server" Text="Button 2">
            <DirectEvents>
                <Click OnEvent="Button_Click">
                    <ExtraParams>
                        <ext:Parameter Name="param3" Value="Button2" Mode="Value" />
                    </ExtraParams>
                </Click>
            </DirectEvents>
        </ext:Button>
    </body>
    </html>
  8. #8
    That's awesome, thanks!

Similar Threads

  1. [CLOSED] ExtraParams in DirectEvents comes back 'null'
    By Fahd in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 22, 2012, 7:44 PM
  2. [CLOSED] Common Direct Methods
    By speedstepmem3 in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Nov 25, 2011, 5:54 AM
  3. Replies: 6
    Last Post: Aug 01, 2011, 4:53 PM

Tags for this Thread

Posting Permissions