[CLOSED] Problem with events order

  1. #1

    [CLOSED] Problem with events order

    Hi, I have a page with a trigger field and a button. the desire behaviour would be: When you introduce an account number text on the trigger field (named tggAccount), on the change event the system gets the associated id (and store it on hddTggAccount). After this, if you click on the search button (btnSearch), the system launchs a search with the id as a filter.

    However, the system doesn't work on that way. The button click event executes before the change trigger field event, so the search doesn't get a coherent id.

    I adjust you my code:

     
                                            <ext:TriggerField ID="tggAccount" runat="server" Width="180" MaxLength="7" AllowBlank="true"
                                                EmptyText="<%$ Resources: tggAccount.SearchCriteria %>" EnableKeyEvents="true"
                                                 Regex="<%$ Resources:RegularExpressions, RegExInt %>"
                                                RegexText="<%$ Resources:RegularExpressions, RegExIntErrorText %>">
                                                <DirectEvents>
                                                    <Change OnEvent="tggAccount_Change">
                                                    </Change>
                                                </DirectEvents>
                                                <Listeners>
                                                    <TriggerClick Fn="tggAccount_TriggerClick" />
                                                </Listeners>
                                            </ext:TriggerField>
                                            <ext:Hidden ID="hddTggAccount" runat="server" Text="" />
     
                                <ext:Button ID="btnSearch" runat="server" Text="<%$Resources: strings, btnSearch_Text %>"
                                    Icon="<%$Resources: strings, btnSearch_Icon %>">
                                    <DirectEvents>
                                        <Click OnEvent="btnSearch_OnClick">
                                            <EventMask ShowMask="true" Msg="<%$Resources: itemLoading %>" />
                                        </Click>
                                    </DirectEvents>
                                </ext:Button>
    Could you give me any suggestion, please?

    Thank u in advance
    Last edited by Daniil; Dec 01, 2010 at 5:57 AM. Reason: [CLOSED]
  2. #2
    on the change event the system gets the associated id (and store it on hddTggAccount)
    Hi,

    Are you sure that this action requires DirectEvent? Could you provide us with tggAccount_Change? Just it's a really good design to avoid DirectEvents as soon as possible - this much increases application's performance.
  3. #3
    Yes, I need to validate that the introduced account number is valid, the account state, etc.. againts the data base, and as soon as possible. All the data base access logic and the whole validation logic are developed on C#, so the unique solution I know is on the change event and through a DirectEvents.

     
    protected void tggAccount_Change(object sender, DirectEventArgs e)
    {
    //Links with the rest of the application
    ...
    }
  4. #4
    Thank you for the clarification.

    I would suggest you the following technique.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        [DirectMethod]
        public string GetID(string value)
        {
            //actions with TriggerField's value
            return "someID";
        }
    
        protected void Button1_Click(object sender, DirectEventArgs e)
        {
            X.MessageBox.Alert("Button1_Click", "Searching is complete").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 getId = function (field, value) {
                Ext.net.DirectMethods.GetID(value, { 
                    success: function(id) { 
                        Button1.enable();
                        field.notAllowChange = true;
                        alert(id); 
                    } 
                });
            }
        </script>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:TriggerField ID="TriggerField1" runat="server">
            <Triggers>
                <ext:FieldTrigger Tag="apply" Icon="SimpleTick" />
                <ext:FieldTrigger Tag="main" />
            </Triggers>
            <Listeners>
                <TriggerClick Handler=" if (tag == 'apply') {
                                            this.notAllowChange = true;
                                            getId(this, this.getValue());
                                        }" />
                <Focus Handler="Button1.disable();" />
                <Change Handler="if (!this.fireChange) {
                                    getId(this, newValue);
                                }" />
            </Listeners>
        </ext:TriggerField>
        <ext:Button ID="Button1" runat="server" Text="Search">
            <DirectEvents>
                <Click OnEvent="Button1_Click">
                    <EventMask ShowMask="true" Msg="Searching..." MinDelay="2500" />
                </Click>
            </DirectEvents>
        </ext:Button>
        </form>
    </body>
    </html>
  5. #5
    Thank you for this proposal. However, after showing this solution to the customer, he hasn't accepted a new trigger on the controls with a change event (of this kind) as you propose :(

    The unique solution I see is, on the button Search click event:

    a) validate if any fields has an Change event pending to execute, and fireEvent for this fields before the search code region.
    b) Be able to execute first the change event before the click event.

    I don't know if one of this are possible or if you have another solution better.

    Sorry for the inconveniences, but I haven't yet more solutions to face this problem.
  6. #6
    Hi,

    What about the following sample
    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }
    
        protected void CheckAccount(object sender, RemoteValidationEventArgs e)
        {
            System.Threading.Thread.Sleep(2000);
            e.Success = true;
        }
    
        protected void btnSearch_OnClick(object sender,DirectEventArgs e)
        {
            X.Js.Alert("Search is complete with id = " + hddTggAccount.Text);
        }
    </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>Ext.Net Example</title>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            
            <ext:Container runat="server" Layout="Form" HideLabels="true">
                <Items>
                
                
            <ext:TriggerField ID="tggAccount" runat="server"             
                Width="180" 
                MaxLength="7" 
                AllowBlank="true" 
                IsRemoteValidation="true">                 
                <RemoteValidation ValidationEvent="change" ShowBusy="true" OnValidation="CheckAccount" />
                <Listeners>
                    <RemoteValidationValid Handler="hddTggAccount.setValue(this.getValue());" />
                </Listeners>
            </ext:TriggerField>
            </Items>
            </ext:Container>
                
            <ext:Hidden ID="hddTggAccount" runat="server" Text="" />
     
            <ext:Button ID="btnSearch" runat="server" Text="Search">
                <DirectEvents>
                    <Click OnEvent="btnSearch_OnClick" Before="var valid = tggAccount.isValid(); if(!valid){alert('Account is not valid or still checking');} return valid;">
                        <EventMask ShowMask="true" Msg="Searching..." />
                    </Click>
                </DirectEvents>
            </ext:Button>
        
        </form>
    </body>
    </html>
    Also, you can disable the button while the field is validated

Similar Threads

  1. [CLOSED] Order GridPanel Groups in an arbitrary order?
    By dmoore in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Dec 27, 2013, 4:35 AM
  2. Replies: 12
    Last Post: Dec 25, 2012, 11:55 AM
  3. [CLOSED] Problem with order of items in Grid to Tree
    By skisly in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Feb 01, 2012, 5:20 PM
  4. [CLOSED] Problem with order of items in Grid to Tree
    By skisly in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Jan 25, 2012, 9:55 PM
  5. [1.0] Rendering order causes problem
    By thchuong in forum 1.x Help
    Replies: 4
    Last Post: Jun 23, 2010, 1:19 AM

Tags for this Thread

Posting Permissions