Apr 01, 2011, 3:09 PM
[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:
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
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?
<%@ 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]