PDA

View Full Version : [CLOSED] Taskmanager - change refresh time in code behind



tanky65
Jul 09, 2012, 3:11 PM
Hi all,
I would change in code behind the Interval time of a Task in the TaskManager pool I defined in my page.

I tried in this way:

in Page_Load method (this works)


try
{
TaskManager1.Tasks[0].Interval = DbTools.getAutoRefresh()*1000;
}
catch (FormatException es)
{
TaskManager1.Tasks[0].Interval = 15000;
}


in the direct event of a button (this doesn't work)


protected void OnChangeRefreshTime(object sender, DirectEventArgs e)
{
TaskManager1.StopTask ('my task');
TaskManager1.Tasks[0].Interval = newvalue;
TaskManager1.StartTask ('my task');
}



it keeps always the initial value.

Tasks[0] is equal 'my task', the only one defined in the pool

Any idea, thanks in advance

Daniil
Jul 09, 2012, 4:57 PM
Hi,

The Interval property is a config option and not applied after the Task is already rendered.

I can suggest the following solution.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void ChangeInterval(object sender, DirectEventArgs e)
{
X.Js.Call("setTaskInterval", new JRawValue(this.TaskManager1.ClientID), "task1", 5000);
}
</script>

<!DOCTYPE>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>

<script type="text/javascript">
var setTaskInterval = function (taskMgr, taskId, newInterval) {
var task = taskMgr.getTask(taskId);

taskMgr.stopTask(task);
task.interval = newInterval;
taskMgr.startTask(task);
};
</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:TaskManager ID="TaskManager1" runat="server">
<Tasks>
<ext:Task TaskID="task1" Interval="2000">
<Listeners>
<Update Handler="console.log('update');" />
</Listeners>
</ext:Task>
</Tasks>
</ext:TaskManager>

<ext:Button runat="server" Text="Change Interval" OnDirectClick="ChangeInterval" />
</form>
</body>
</html>

tanky65
Jul 09, 2012, 6:47 PM
Hi,

The Interval property is a config option and not applied after the Task is already rendered.

I can suggest the following solution.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void ChangeInterval(object sender, DirectEventArgs e)
{
X.Js.Call("setTaskInterval", new JRawValue(this.TaskManager1.ClientID), "task1", 5000);
}
</script>

<!DOCTYPE>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>

<script type="text/javascript">
var setTaskInterval = function (taskMgr, taskId, newInterval) {
var task = taskMgr.getTask(taskId);

taskMgr.stopTask(task);
task.interval = newInterval;
taskMgr.startTask(task);
};
</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:TaskManager ID="TaskManager1" runat="server">
<Tasks>
<ext:Task TaskID="task1" Interval="2000">
<Listeners>
<Update Handler="console.log('update');" />
</Listeners>
</ext:Task>
</Tasks>
</ext:TaskManager>

<ext:Button runat="server" Text="Change Interval" OnDirectClick="ChangeInterval" />
</form>
</body>
</html>


Hi Daniil,
thanks a lot for claryfing the rendering aspect.
your prompt suggestion works simply well.
Bye,
solved

Daniil
Jul 09, 2012, 7:50 PM
We hope to provide some better mechanism to update the Task properties on the fly.

We will update the thread when we will come up with any solution.

Daniil
Jan 13, 2013, 5:27 AM
Hi @tanky65,

We have added the SetTaskInterval server method.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void ChangeInterval(object sender, DirectEventArgs e)
{
this.TaskManager1.SetTaskInterval("task1", 5000);
}
</script>

<!DOCTYPE>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:TaskManager ID="TaskManager1" runat="server">
<Tasks>
<ext:Task TaskID="task1" Interval="2000">
<Listeners>
<Update Handler="console.log('update');" />
</Listeners>
</ext:Task>
</Tasks>
</ext:TaskManager>

<ext:Button
runat="server"
Text="Change Interval (client side)"
Handler="App.TaskManager1.setTaskInterval('task1', 1000)" />

<ext:Button
runat="server"
Text="Change Interval (server side)"
OnDirectClick="ChangeInterval" />
</form>
</body>
</html>

tanky65
Jan 13, 2013, 9:56 AM
many thanks Daniil,
can you tell me just how to get this update ?


Hi @tanky65,

We have added the SetTaskInterval server method.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void ChangeInterval(object sender, DirectEventArgs e)
{
this.TaskManager1.SetTaskInterval("task1", 5000);
}
</script>

<!DOCTYPE>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:TaskManager ID="TaskManager1" runat="server">
<Tasks>
<ext:Task TaskID="task1" Interval="2000">
<Listeners>
<Update Handler="console.log('update');" />
</Listeners>
</ext:Task>
</Tasks>
</ext:TaskManager>

<ext:Button
runat="server"
Text="Change Interval (client side)"
Handler="App.TaskManager1.setTaskInterval('task1', 1000)" />

<ext:Button
runat="server"
Text="Change Interval (server side)"
OnDirectClick="ChangeInterval" />
</form>
</body>
</html>

Daniil
Jan 13, 2013, 1:37 PM
It is here:
http://svn.ext.net/premium/trunk/

Please notice that it uses ExtJS 4.2.0 beta 2. So, it is unstable, but you can give it a try.