|
Rank: Member Groups: Member
Joined: 6/21/2007 Posts: 15
|
Maybe I am missing something here but I will explain what I need to do.
I have a page that lets someone pick a bunch of items. Then they click a button and it begins the process. In this case it is sending out a bunch of email invitations. This is a long process because there could be thousands of them.
Here is my problem. I do not want the progress bar to be visible until the button is clicked. I am having a great deal of trouble making this happen. I need to progress bar to only be visible durring the process and then it needs to go away. This page is complex enough without a progress bar showing when it should not be there.
The other problem I am having is that after the process is complete I need to change the form by repopulating a dropdown list and rebinding a grid control. While trying to do this within the RunTask event on the server side it does everything great....Meaning it sends all the email messages but after the task completes it will not do anything else.
Example code:
This is an invitation system It displays a list of users that someone can select with checkboxes in a datalist
Protected Sub ProgressBar1_RunTask(ByVal sender As Object, ByVal e As EO.Web.ProgressTaskEventArgs) Handles ProgressBar1.RunTask Dim a As Integer Dim max As Integer = ProgressBar1.Maximum For Each item As DataListItem In DataList1.Items 'Do my send email here. e.UpdateProgress(a, "Working") System.Threading.Thread.Sleep(100) End If Next e.UpdateProgress(a, "All invitation have been sent") 'Rebind the the datalist here reloaddropdown 'Reloads a drop down to remove a group of people that already got invites. reloaddatalist() 'Rebinds the datalist to show only users that did not get an invite end sub
In the above example it does not reload the dropdown or rebind the datalist. Am I missing something. I tried everything I could think of but it seems like it can do anything other than update the progress bar. I even placed everything into an update panel but it just will not work.
If this can not be done in the RunTask event on the server side as suspect is the case then is it even possible to do another way.
Help!!!!!
- Paul
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,193
|
Hi, These posts should answer your questions: http://www.essentialobjects.com/Forum/Default.aspx?g=posts&t=1750http://www.essentialobjects.com/Forum/Default.aspx?g=posts&t=1716You will need to rely on JavaScript code to update anything other than the ProgressBar itself --- this typically means raising a postback or an AJAX callback from JavaScript since server side code has to be called somehow. Thanks
|
|
Rank: Member Groups: Member
Joined: 6/21/2007 Posts: 15
|
I am not sure what you mean by raiising a postback. How can this be done. Do you have an example that raises a postback inside the RunTask? or an example of a callback to run the server side code during this process. I looked at the examples but they do not have anything like this in them. Sorry for my ignorance here.
- Paul
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,193
|
Hi,
You missed our point. Two points in our previous rely:
1. You can not do that in RunTask; 2. You need to do it in your client side JavaScript code;
This usually means:
1. You pass a special variable to your client side OnProgress JavaScript handler inside RunTask with e.UpdateProgress; 2. Your client side OnProgress handler checks for the special value and if it sees it, it raises a postback. Details about raising postback or AJAX callback would be outside the scope of our support (as it is a generic ASP.NET/web programming issue that are not related to our product). Generally you can call __doPostBack, which is provided by ASP.NET; or use an AJAX solution such as our CallbackPanel (which requires a license). We would be happy to produce a sample if you purchase a license for the CallbackPanel control; 3. This postback/callback raised by your JavaScript code then trigger some other server side code, where you would then update whatever you need. This step essentially has nothing to do with ProgressBar;
Hope this helps.
Thanks
|
|
Rank: Member Groups: Member
Joined: 6/21/2007 Posts: 15
|
I have a license for the callback control. I recently paid for the lastest suite of controls you have. Please check your records. I am in a time crunch here. I am not a good javascript programmer I am kind of lost as to how to do this. Can you proivide me with a simple example of how to do this. I would really appeciate any help you can provide here.
- Paul
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,193
|
Not a problem. We will produce a working example that uses the CallbackPanel to trigger an AJAX Callback that updates a server side control, such as a Label. You can then replace the Label to whatever you would like. We will try to get this either to you tonight or tomorrow.
|
|
Rank: Member Groups: Member
Joined: 6/21/2007 Posts: 15
|
Thank you so much for the help.
- Paul
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,193
|
Hi, The following code is based on the "Server Side Task" sample: 1. Append the following HTML code to Demo.ascx after "divStatus":
Code: HTML/ASPX
<eo:CallbackPanel runat="server" id="CallbackPanel1">
<asp:Label id="Label1" Runat="server"></asp:Label>
</eo:CallbackPanel>
The code defines an AJAX update region that contains a single Label control, which we will update when RunTask is done; 2. Change JavaScript function OnProgress as follow:
Code: JavaScript
function OnProgress(progressBar)
{
var extraData = progressBar.getExtraData();
if (extraData)
{
//The following code demonstrates how to update
//client side DHTML element based on the value
//RunTask passed to us with e.UpdateProgress
var div = document.getElementById("divStatus");
div.innerHTML = extraData;
//The following code demonstrates how to update
//server side control based on the value RunTask
//passed to us with e.UpdateProgress
if (extraData == "The task is done!")
{
//Trigger an AJAX callback using the CallbackPanel
//control. This will trigger the server side
//CallbackPanel1_Execute event handler. See the
//documentation for more details on how to use the
//CallbackPanel control. Note we must use setTimeout
//here to delay the call until the ProgressBar is done
//because while the ProgressBar is running, the page
//is in a special state that can not update anything
//but the ProgressBar (This is also why update other
//controls inside RunTask does not work)
window.setTimeout(
"eo_Callback('<%=CallbackPanel1.ClientID%>')",
10);
}
}
}
3. Attach the following event handler to CallbackPanel1's Execute event:
Code: C#
private void CallbackPanel1_Execute(
object sender, EO.Web.CallbackEventArgs e)
{
Label1.Text = "Task done at " + DateTime.Now.ToString();
}
When the program runs, RunTask runs as normal until it finishes, at which points it calls:
Code: C#
e.UpdateProgress(100, "The task is done!");
Where "The task is done!" is a value checked by client side JavaScript handler OnProgress. When OnProgress sees this value, it calls eo_Callback to trigger an AJAX callback. This calls CallbackPanel1_Execute server side event handler, at which point the page has already been put back to "normal" state and you are free to update anything --- in this case a Label control. Hope this helps. Thanks
|
|
Rank: Member Groups: Member
Joined: 6/21/2007 Posts: 15
|
Once again I find your support of your product to be outstanding. Thank you for your quick and correct response to my problem.
I figured in case someone else is having the same problem as me I would post the complete solution. This is an example of how to make the progress bar visible right before the task starts and invisible after the task completes and also update any control on the form after the progress bar does its thing.
ASPX code. _________________________________________________________________________________ <%@ Page Language="VB" AutoEventWireup="false" CodeFile="atest.aspx.vb" Inherits="atest" %> <%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>
<!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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <script type="text/javascript"> function start_progress_bar() { //Hide whatever you want to hide document.getElementById("div1").style.display = "inline"; document.getElementById("Label1").style.display = "none"; document.getElementById("mybutton").disabled = "true";
//Get the progress bar object var pb = eo_GetObject("ProgressBar1");
//Start the progress bar pb.startTask(); } function OnProgress(progressBar) { var extraData = progressBar.getExtraData(); if (extraData) { var div = document.getElementById("divStatus"); div.innerHTML = extraData; if (extraData == "The task is done!") { document.getElementById("div1").style.display = "none"; var div = document.getElementById("divStatus"); div.innerHTML = ' '; document.getElementById("mybutton").disabled = false; window.setTimeout( "eo_Callback('<%=CallbackPanel1.ClientID%>')", 10); } } } </script> <div id="div1" runat="server" style="display:none" > <eo:ProgressBar ID="ProgressBar1" runat="server" Width="250px" ClientSideOnValueChanged="OnProgress" BorderColor="Transparent" BorderStyle="Solid" BorderWidth="1px" ControlSkinID="None" Height="16px" IndicatorColor="DodgerBlue" ShowPercentage="True" BackColor="Silver" Font-Names="Verdana" Font-Size="Medium" ForeColor="White"> </eo:ProgressBar> </div> <eo:CallbackPanel runat="server" id="CallbackPanel1"> <asp:Label ID="Label1" runat="server" Font-Names="Verdana"></asp:Label><br /><br /> <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList><br /> </eo:CallbackPanel> <div id="divStatus" style="font-family:Verdana;color:black;font-size:large"></div><br /> <input type="button" id="mybutton" value="Start" onclick="start_progress_bar()" /> </form> </body> </html> ________________________________________________________________________________
Code Behind. ________________________________________________________________________________ Partial Class atest Inherits System.Web.UI.Page Protected Sub ProgressBar1_RunTask(ByVal sender As Object, ByVal e As EO.Web.ProgressTaskEventArgs) Handles ProgressBar1.RunTask Dim a As Integer = 0 For a = 1 To 99 e.UpdateProgress(a, "Sending " + a.ToString + " of 100") System.Threading.Thread.Sleep(100) Next e.UpdateProgress(100, "The task is done!") End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ProgressBar1.Maximum = 100 Dim a As Integer = 0 If Not IsPostBack = True Then DropDownList1.Items.Clear() For a = 1 To 100 Dim myitem As New ListItem myitem.Value = a myitem.Text = a.ToString DropDownList1.Items.Add(myitem) Next End If End Sub Protected Sub CallbackPanel1_Execute(ByVal sender As Object, ByVal e As EO.Web.CallbackEventArgs) Handles CallbackPanel1.Execute Label1.Text = "All Invitations have been sent" Dim a As Integer = 0 DropDownList1.Items.Clear() For a = 200 To 300 Dim myitem As New ListItem myitem.Value = a myitem.Text = a.ToString DropDownList1.Items.Add(myitem) Next End Sub End Class _________________________________________________________________________________
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,193
|
Awesome. Thanks for sharing!
|
|