Feb 13, 2012, 11:58 AM
Progressbar code behind
Hello,
I want to try something out: On the examples page there is an example of a progressbar.
[default.aspx]
But now I want an EQUIVALANT version of this in code behind.
This is my guess:
[default.aspx.cs]
I want to try something out: On the examples page there is an example of a progressbar.
[default.aspx]
<script type="text/javascript">
var updateBar = function(value, pbar, btn, count, callback) {
if (value > count) {
btn.setDisabled(false);
callback();
} else {
pbar.updateProgress(value / count, 'Loading item ' + value + ' of ' + count + '...');
}
}
var run = function(pbar, btn, count, callback) {
btn.setDisabled(true);
var ms = 5000 / count;
for (var i = 1; i < (count + 2); i++) {
setTimeout(updateBar.createCallback(i, pbar, btn, count, callback), i * ms);
}
}
var runProgress1 = function(status, progress, btn) {
status.setText('Working');
progress.show();
run(progress, btn, 10, function() {
progress.reset(true);
status.setText('Done.');
});
}
</script>
<body>
<form id="batchGUI" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<br />
<p>
<b>1. Basic Progress Bar</b><br />
Dynamic show/hide and built-in progress text:
<ext:Button ID="ShowProgress1" runat="server" Text="Show">
<Listeners>
<Click Handler="runProgress1(#{StatusLabel}, #{Progress1}, this);" />
</Listeners>
</ext:Button>
<br />
<ext:Label ID="StatusLabel" runat="server" Cls="status" Text="Nothing to see here." />
<ext:ProgressBar ID="Progress1" runat="server" Width="300" Text="Initializing..."
Hidden="true" />
</p>
</form>
</body>
-------------------------------------------------------------------------------------------------------------------------------------But now I want an EQUIVALANT version of this in code behind.
This is my guess:
[default.aspx.cs]
[DirectMethod]
public void runProgress1(Ext.Net.Label status, Ext.Net.ProgressBar progress, Ext.Net.Button btn)
{
status.Set("Working2", status);
progress.Show();
run(progress, btn, 10, function() // What to do with this? function does not exist in current context
{
progress.Reset(true);
status.Set("Done.", status);
});
}
[DirectMethod]
public void run(Ext.Net.ProgressBar pbar, Ext.Net.Button btn, int count, callback)
{
btn.Disabled = true;
var ms = 5000 / count;
for (var i = 1; i < (count + 2); i++)
{
setTimeout(updateBar.createCallback(i, pbar, btn, count, callback), i * ms); // setTimeout does not exist in current context.
}
}
[DirectMethod]
public void updateBar(int value, Ext.Net.ProgressBar pbar, Ext.Net.Button btn, int count, callback)
{
if (value > count)
{
btn.Disabled = false;
callback(); // callback() does not exist in the current context
}
else
{
pbar.UpdateProgress((value / count), "Loading item " + value + " of " + count + "...");
}
}
PS: as for why I want codebehind is because instead of (var ms = 5000 / count) I need to use my own code. That's for every succesful method called on object X, e.g. if method "add" is success then int success++ something like this.
Last edited by HaamSapTjai; Feb 13, 2012 at 2:15 PM.