[CLOSED] DirectMethod call - setting control visibility doesn't work

  1. #1

    [CLOSED] DirectMethod call - setting control visibility doesn't work

    I have a webform containing an Ext Label and an Ext Button. The markup and code behind are as follows:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DMTest.aspx.cs" Inherits="TWA.DMTest" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!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></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <div style="font-family:Arial,Sans-Serif;font-size:10pt">
    <p>Some random text xxx yyy zzz</p>
    <ext:Label runat="server" ID="LabelRoles" />
    <ext:Button runat="server" ID="ButtonRefreshRoles" Text="Refresh label" StyleSpec="margin-top:0.5em" >
      <Listeners>
        <Click Handler="this.setText('Refreshing...');Ext.net.DirectMethods.UpdateLabel();" />
      </Listeners>
    </ext:Button>
    </div>
    </form>
    </body>
    </html>
    the code-behind
        public partial class DMTest : System.Web.UI.Page
        {
            public bool ReturnValue
            {
                get
                {
                    var s = System.Configuration.ConfigurationManager.AppSettings["returnValue"];
                    return s == "1";
                }
            }
    
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!X.IsAjaxRequest)
                {
                    string RolesMsg = GetLabelText();
                    LabelRoles.Text = RolesMsg;
                    if (!LabelRoles.Text.StartsWith("1:"))
                    {
                        LabelRoles.Element.Highlight();
                        ButtonRefreshRoles.Visible = false;
                    }
    
                }
            }
    
            [DirectMethod]
            public void UpdateLabel()
            {
                LabelRoles.Text = GetLabelText();
                System.Threading.Thread.Sleep(2000);
                ButtonRefreshRoles.Text = "Refresh label";
                if (!LabelRoles.Text.StartsWith("1:"))
                {
                    ButtonRefreshRoles.Visible = false;
                    LabelRoles.Element.Highlight();
                }
            }
    
            public string GetLabelText()
            {
                return ReturnValue ?
                    "1: Return value is set and the button is visible" :
                    "0: Return value not set and the button is invisible";
            }
        }
    As you can see, the label's text in both the Page_Load and UpdateLabel Direct method is set according to the value of the returnValue appSetting item, and when this is set to 1, the appropriate message is displayed and the refresh button is visible. On pressing the pushbutton, the button text changes to "Refreshing...", the DirectMethod UpdateLabel is called, the returnValue is read from the appSetting and the label is updated as appropriate, and the button text is reset to "Refresh label". So far so good.

    If I change the returnValue appSetting to 0, then press the Refresh Label button, the button text changes to "Refreshing...", the Direct method returns and set the label text as appropriate but the button's text isn't reset and the button isn't made invisible by the call to
    ButtonRefreshRoles.Visible = false;
    If I alter the code-behind to comment-out the
    ButtonRefreshRoles.Visible = false;
    in the DirectMethod, then the button text is reset correctly.

    It seems that the DirectMethod isn't working correctly in not making the button control invisible. Or am I doing something wrong? Or is setting a control's visibility from the server side not supported from DirectMethods?
    Last edited by Daniil; Apr 03, 2011 at 10:00 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Yes, changing .Visible during DirectEvebt/DirectMethod doesn't make any sense.

    Please use .Hidden.
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi,

    Yes, changing .Visible during DirectEvebt/DirectMethod doesn't make any sense.

    Please use .Hidden.
    Thanks.

    But why doesn't it make sense to change .Visible? Surely that'd just translate into an ExtJS .setVisible() method call on the control/component?
  4. #4
    Hi,

    Visible and Hidden are not the same.
    If Visible=false then a widget is not rendered at all (it is absent on client side) therefore we cannot change visibility on client side. You have to rerender the widget after set Visible=true during DirectEvent
    Widget1.Render();
    If Hidden=true then the widget is rendered but hidden in the browser, you can easly to control visiblilty in the client side by Hidden property during DirectEvent
  5. #5
    Quote Originally Posted by Vladimir View Post
    Hi,

    Visible and Hidden are not the same.
    If Visible=false then a widget is not rendered at all (it is absent on client side) therefore we cannot change visibility on client side. You have to rerender the widget after set Visible=true during DirectEvent
    Widget1.Render();
    If Hidden=true then the widget is rendered but hidden in the browser, you can easly to control visiblilty in the client side by Hidden property during DirectEvent
    Thanks, that makes sense.

Similar Threads

  1. [CLOSED] Call DirectMethod from subclassed control
    By smart+ in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jun 08, 2011, 10:05 AM
  2. [CLOSED] GridPanel Cell Tooltips doesn't work in user control
    By skisly in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: May 09, 2011, 1:57 PM
  3. [CLOSED] Direct Methods with return doesn't work in user control
    By sharif in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Nov 13, 2010, 12:00 PM
  4. Replies: 4
    Last Post: Feb 09, 2010, 6:14 PM
  5. [CLOSED] spotlight doesn't work properly with window control
    By LeeTheGreek in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Nov 10, 2009, 2:43 PM

Tags for this Thread

Posting Permissions