Welcome Guest Search | Active Topics | Sign In | Register

Progress Bar - Stop the task from code behind Options
Molior
Posted: Friday, October 12, 2007 8:29:45 AM
Rank: Newbie
Groups: Member

Joined: 10/12/2007
Posts: 2
Hi EO

Firstly thank you for a fine set of controls.

I am trying to find a way to stop the progress bar task (runtask) on an error and redirect to another page, is there a way to do this?

Please see code comments below:

Code: Visual Basic.NET
Private Sub ProgressBar1_RunTask(ByVal sender As Object, ByVal e As EO.Web.ProgressTaskEventArgs) Handles ProgressBar1.RunTask
        If Not lblUploadedFile.Text = String.Empty Then

            context.Items.Add("task", "pricing data")
            context.Items.Add("process", "Update")

            Try
                Dim ErrorCode As String = "0"
                Dim BackupPath As String = "\DataBackup\Pricing"

                '// Back the current table data to a text file
                ErrorCode = SqlHelper.ExecuteScalar(ConfigurationSettings.AppSettings.Item("ConnString"), "spBackupTable_ToFile", "pricing", BackupPath, ",")
                If Not ErrorCode = "0" Then
                    context.Items.Add("errorcode", "Error backing up current data - " & ErrorCode)
                    context.Items.Add("error", "true")
                    '// ** if error then stop the run task process and exit try for redirect to error page
                    Exit Try
                Else
            
                  '//Run more code . . . . .

            Catch ex As Exception
                context.Items.Add("errorcode", "Unspecified error")
                context.Items.Add("error", "true")
            End Try

            '// ** run task cancels, but page not updated and does not process redirect **
            Response.Redirect("dbProcessResult.aspx", True)
            'Server.Transfer("dbProcessResult.aspx", True)

        End If
    End Sub


eo_support
Posted: Friday, October 12, 2007 8:35:35 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You can stop the task whenever you want simply by exiting the function. However you won't be able to do Redirect on the server side. The easiest way would be call e.UpdateProgress and use the second parameter to pass a special value to the client (maybe the new page Url, for example), then handle ClientSideOnProgress event and do a client side redirect from there.

Thanks
Molior
Posted: Friday, October 12, 2007 9:27:52 AM
Rank: Newbie
Groups: Member

Joined: 10/12/2007
Posts: 2
Hi Admin,

Thanks for such a quick reply - do you have a code example that I could follow, or a pointer in the correct direction?

Many thanks.
eo_support
Posted: Friday, October 12, 2007 9:44:04 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Yes. Here you go:

Server side code:

Code: Visual Basic.NET
Private Sub ProgressBar1_RunTask(
    ByVal sender As Object, ByVal e As EO.Web.ProgressTaskEventArgs) 
    Handles ProgressBar1.RunTask

    ....perform other tasks.....

   'Now redirect to http://www.essentialobjects.com. UpdateProgress
   'itself actually has nothing to do with Redirect. It only passes the
   'target Url to the client side, the client side code then perform the
   'redirection
   e.UpdateProgress(50, "http://www.essentialobjects.com")

End Sub


Client Side Code:

Code: JavaScript
//This function is associated with the progress bar
//through the progress bar's ClientSideOnValueChanged
//property 
function on_progress(progressBar)
{
    //The second argument of UpdateProgress is passed to
    'the client and can be retrieved by getExtraData
    var url = progressBar.getExtraData();

    //Perform the redirection
    if (url)
        window.open(url, "_self");
}


Code: HTML/ASPX
<eo:ProgressBar 
     ClientSideOnValueChanged="on_progress" .....>
</eo:ProgressBar>


That should get you going.

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.