[CLOSED] Disable some Controls before DirectMethod

  1. #1

    [CLOSED] Disable some Controls before DirectMethod

    Hello,
    Is there any way to disable a control (Panel, GridPanel, Window etc) just before firing direct-method?

    I'm trying to achieve in my sample code:
    - When the button is clicked, the panel should be disabled immediatelly (page should be updated)
    - Now the button1_click (direct-method) fires and takes some time to finish
    - After that, the panel gets enabled

    Ext.Net 1.5.0
    Framework 4
    IE 8

    P.

    using System;
    using System.Collections.Generic;
    using System.Web;
    using Ext.Net;
    
    public partial class test5 : System.Web.UI.Page
    {
        Panel panel1;
    
        [DirectMethod]
        public void button1_click()
        {
          // takes some time to load...
          panel1.Html = "Panel is now loaded.";
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
    
          ResourceManager res_man = new ResourceManager();
          res_man.ID = "res_man";
          this.Controls.Add(res_man);
    
          panel1 = new Panel();
          panel1.ID = "panel1";
          panel1.Height = 200;
          panel1.Width = 200;
    
          Ext.Net.Button button1 = new Ext.Net.Button();
          button1.ID = "button1";
          button1.Text = "Load panel";
    
          button1.Listeners.Click.Handler = "#{panel1}.setDisabled(true);";
          button1.Listeners.Click.Handler += "#{DirectMethods}.button1_click();";
          button1.Listeners.Click.Handler += "#{panel1}.setDisabled(false);";
    
          this.Form.Controls.Add(panel1);
          this.Form.Controls.Add(button1);
        }
    }
    Last edited by Daniil; Aug 18, 2012 at 9:39 AM. Reason: [CLOSED]
  2. #2
    Hi,

    You should move
    #{panel1}.setDisabled(false);
    into a success (probably, to a failure one as well) handler of DirectMethod.

    Example
    new Ext.Net.Button().Listeners.Click.Handler += @"#{DirectMethods}.button1_click({
                                                            success : function () {
                                                                #{panel1}.setDisabled(false);
                                                            }
                                                        });";
  3. #3
    Thanks for the suggestion :)

    The aim was to disable the panel before long lasting data processing (panel loading) so I did:
        [DirectMethod]
        public void disable_panel()
        {
          panel1.Disabled = true;
        }
    
        [DirectMethod]
        public void load_data()
        {
          try
          {
            // may take some time to load...
            panel1.Html = "Panel is now loaded.";
          }
          finally
          {
            //then enable panel
            panel1.Disabled = false;
          }
        }
    and the click handler:

    button1.Listeners.Click.Handler += @"#{DirectMethods}.disable_panel({ success : function () { #{DirectMethods}.load_data(); } });";
  4. #4
    I think you could avoid one DirectMethod. The following should work as well.
    button1.Listeners.Click.Handler += "#{panel1}.disable(); #{DirectMethods}.load_data()";
    Also you can use the DirectMethod "eventMask" config option instead of disabling. Please see #6 here:
    https://examples1.ext.net/#/Events/D...hods/Overview/
    Last edited by geoffrey.mcgill; Aug 16, 2012 at 1:48 PM.
  5. #5
    You're right, thanks.

    Today I've learned what is the difference between:

     button1.Listeners.Click.Handler = "#{panel1}.setDisabled(true);";       
     button1.Listeners.Click.Handler += "#{DirectMethods}.button1_click();";
    and

     button1.Listeners.Click.Handler = "#{panel1}.setDisabled(true); #{DirectMethods}.button1_click();";
    (and not to use the first one just to avoid long strings)

    Regards,
    PK
  6. #6
    Seems there is no any logical difference between these pieces.

    Could you clarify what you mean?
  7. #7
    I'm sorry for creating confusion. There is no difference between these pieces of code.

    In my "working" example I had:
    button1.Listeners.Click.Handler = "#{panel1}.disable();";       
    button1.Listeners.Click.Handler += "#{DirectMethods}.load_data()";
    button1.Listeners.Click.Handler += "#{panel1}.enable();";
    And this is not disabling the panel before "load_data()"; The answer to my question was to remove the "enable();" and put it (analogous code) into "load_data()".

    Now it works fine.

    Regards,
    PK
    Last edited by Daniil; Aug 21, 2012 at 9:01 AM. Reason: Please use [CODE] tags
  8. #8
    Yes, that is right. Thanks for clarification.

Similar Threads

  1. Replies: 2
    Last Post: Apr 27, 2011, 8:08 AM
  2. Replies: 12
    Last Post: Mar 24, 2011, 5:38 PM
  3. [CLOSED] Disable/Readonly controls
    By Hari_CSC in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 30, 2010, 2:15 AM
  4. [CLOSED] How to disable/enable all controls in formpanel
    By idrissb in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Oct 13, 2009, 12:21 PM
  5. Disable controls
    By Argons in forum 1.x Help
    Replies: 3
    Last Post: Aug 04, 2009, 1:03 PM

Posting Permissions