How to make visible an image (gif anim.) while wait for a task to finish

P

pamelafluente

I am reposting hoping better luck :)

I can't achieve this simple thing: I have an animated gif in an image
control (ImageProgress1). The image visibility is set to false. I want
that when the User click on a given button (ButtonSomeLongTask) to
execute a long task Me.ImageProgress1 become visible until the task on
the server is finished. I call the task this way:

Protected Sub ButtonSomeLongTask_Click(ByVal sender As Object, ByVal
e As System.EventArgs) Handles ButtonSomeLongTast.Click
ExecuteLongTask() 'here there is a call to a web service
End Sub

Any *simple* example to do it?

-Pam
 
B

bruce barker \(sqlwork.com\)

this will not work. in the asp.net from processing model, a button click
posts back, and the page is rebuilt and sent back to the browser. this means
the brwser will not see the html to display the gif until all the server
processing is done.

you can set the gif with client code, but in general animated gifs will not
run during a postback. the best solution is start the long running process
in a background thread, and poll for completion. google this newgroup for
processing message, and you shoudl find examples.

-- bruce (sqlwork.com)
 
P

pamelafluente

I see :( Thanks bruce.
Apart animated gif, is there any simple solution I can use to entertain
the user during a long running task, possibly without spending a week
to implement it ? I have seen some of such nice animations, but I am
unsure about the technology they used.

-Pam

bruce barker (sqlwork.com) ha scritto:
 
M

mc

How About:-

place the gif on the page and set it's style to "display:none" then in
your code set the onClientClick to some Javascript which un-hides the
image, this will then be visible to the user until the post back has
been completed and the new page is sent out?

never actually tried this myself but it seems to make sense in my head!

Have you thought about Atlas? You can use an update progress control to
display some custom text/graphic whilst the Ajax post back is completing.
 
P

pamelafluente

hmmm, no it does not seem to work. If you have it working please let me
know.

Perhaps the images must be animated manually by javascript.

-p

mc ha scritto:
 
M

mc

I've just quickly knocked up a prototpye with an animated gif

I have a page as follows

[PAGE HEADER STUFF]
....
<asp:Image ID="progressImage" ImageUrl="~/progBall.gif" runat="server"/>
<asp:Button ID="DoLongTaskButton" runat="server"
OnClick="LongTaskSimulation" Text="Do Long Task" />
....
[PAGE FOOTER STUFF]

and a C# code behind as follows

[STANDARD USINGS]
[CLASS DEFINITION]
....
protected void Page_Load(object sender, EventArgs e)
{
ProgrssImage.Style.Add("display", "none");
DoLongTaskButton.OnClientClick =
"document."+progressImage.ClientID+".style.display = '';";
}

protected void LongTaskSimulation(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
}
....
 
M

mc

I only tested it in Firefox, looks like if you want this to work
universally your OnClientClick needs to read
"document.getElementById('"+progressImage.ClientId+"').style.display = '';"
I've just quickly knocked up a prototpye with an animated gif

I have a page as follows

[PAGE HEADER STUFF]
...
<asp:Image ID="progressImage" ImageUrl="~/progBall.gif" runat="server"/>
<asp:Button ID="DoLongTaskButton" runat="server"
OnClick="LongTaskSimulation" Text="Do Long Task" />
...
[PAGE FOOTER STUFF]

and a C# code behind as follows

[STANDARD USINGS]
[CLASS DEFINITION]
...
protected void Page_Load(object sender, EventArgs e)
{
ProgrssImage.Style.Add("display", "none");
DoLongTaskButton.OnClientClick =
"document."+progressImage.ClientID+".style.display = '';";
}

protected void LongTaskSimulation(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
}
...


hmmm, no it does not seem to work. If you have it working please let me
know.

Perhaps the images must be animated manually by javascript.

-p

mc ha scritto:
 
P

pamelafluente

Perhaps I have not explained well my problem. Looks like you are not
leaving the page at all. The sleep should be put on another page to
simulate the server processing:

source page: button -> some post -> enable animation before leaving
destination page: sleep a while + response write.

during the sleep a while I would like to see some entertainment on the
source page

IE does not animate gif while leaving the page. That's the problem...
If you do the sleep within your page there is no problem.

-p

mc ha scritto:
I only tested it in Firefox, looks like if you want this to work
universally your OnClientClick needs to read
"document.getElementById('"+progressImage.ClientId+"').style.display = '';"
I've just quickly knocked up a prototpye with an animated gif

I have a page as follows

[PAGE HEADER STUFF]
...
<asp:Image ID="progressImage" ImageUrl="~/progBall.gif" runat="server"/>
<asp:Button ID="DoLongTaskButton" runat="server"
OnClick="LongTaskSimulation" Text="Do Long Task" />
...
[PAGE FOOTER STUFF]

and a C# code behind as follows

[STANDARD USINGS]
[CLASS DEFINITION]
...
protected void Page_Load(object sender, EventArgs e)
{
ProgrssImage.Style.Add("display", "none");
DoLongTaskButton.OnClientClick =
"document."+progressImage.ClientID+".style.display = '';";
}

protected void LongTaskSimulation(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
}
...


hmmm, no it does not seem to work. If you have it working please let me
know.

Perhaps the images must be animated manually by javascript.

-p

mc ha scritto:


How About:-

place the gif on the page and set it's style to "display:none" then in
your code set the onClientClick to some Javascript which un-hides the
image, this will then be visible to the user until the post back has
been completed and the new page is sent out?

never actually tried this myself but it seems to make sense in my head!

Have you thought about Atlas? You can use an update progress control to
display some custom text/graphic whilst the Ajax post back is
completing.


(e-mail address removed) wrote:

I see :( Thanks bruce.
Apart animated gif, is there any simple solution I can use to entertain
the user during a long running task, possibly without spending a week
to implement it ? I have seen some of such nice animations, but I am
unsure about the technology they used.

-Pam

bruce barker (sqlwork.com) ha scritto:



this will not work. in the asp.net from processing model, a button
click
posts back, and the page is rebuilt and sent back to the browser.
this means
the brwser will not see the html to display the gif until all the
server
processing is done.

you can set the gif with client code, but in general animated gifs
will not
run during a postback. the best solution is start the long running
process
in a background thread, and poll for completion. google this
newgroup for
processing message, and you shoudl find examples.

-- bruce (sqlwork.com)



I am reposting hoping better luck :)

I can't achieve this simple thing: I have an animated gif in an image
control (ImageProgress1). The image visibility is set to false. I
want
that when the User click on a given button (ButtonSomeLongTask) to
execute a long task Me.ImageProgress1 become visible until the
task on
the server is finished. I call the task this way:

Protected Sub ButtonSomeLongTask_Click(ByVal sender As Object, ByVal
e As System.EventArgs) Handles ButtonSomeLongTast.Click
ExecuteLongTask() 'here there is a call to a web service
End Sub

Any *simple* example to do it?

-Pam
 
M

mc

I do not load a separate page because this is not necessary, I do
however post back to the server (just look for the standard page loading
gif in your chosen browser), the Sleep is being done on the server all
you need to do is replace the function in the asp page
"LongTaskSimulation" with your long task.

Once the task is complete the server will return control to the page
which can be updated with info from the longTask.

Alternatively if you must navigate away to another page place a
Response.Redirect after your long task code and you will then progress
to the next page?

This conforms to the way pages should be developed with the event
processing for the buttons on within the same "module" as the buttons

If this still confuses I suggest you have a search for info on the
ASP.NET page life cycle.

Perhaps I have not explained well my problem. Looks like you are not
leaving the page at all. The sleep should be put on another page to
simulate the server processing:

source page: button -> some post -> enable animation before leaving
destination page: sleep a while + response write.

during the sleep a while I would like to see some entertainment on the
source page

IE does not animate gif while leaving the page. That's the problem...
If you do the sleep within your page there is no problem.

-p

mc ha scritto:

I only tested it in Firefox, looks like if you want this to work
universally your OnClientClick needs to read
"document.getElementById('"+progressImage.ClientId+"').style.display = '';"
I've just quickly knocked up a prototpye with an animated gif

I have a page as follows

[PAGE HEADER STUFF]
...
<asp:Image ID="progressImage" ImageUrl="~/progBall.gif" runat="server"/>
<asp:Button ID="DoLongTaskButton" runat="server"
OnClick="LongTaskSimulation" Text="Do Long Task" />
...
[PAGE FOOTER STUFF]

and a C# code behind as follows

[STANDARD USINGS]
[CLASS DEFINITION]
...
protected void Page_Load(object sender, EventArgs e)
{
ProgrssImage.Style.Add("display", "none");
DoLongTaskButton.OnClientClick =
"document."+progressImage.ClientID+".style.display = '';";
}

protected void LongTaskSimulation(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
}
...


(e-mail address removed) wrote:


hmmm, no it does not seem to work. If you have it working please let me
know.

Perhaps the images must be animated manually by javascript.

-p

mc ha scritto:



How About:-

place the gif on the page and set it's style to "display:none" then in
your code set the onClientClick to some Javascript which un-hides the
image, this will then be visible to the user until the post back has
been completed and the new page is sent out?

never actually tried this myself but it seems to make sense in my head!

Have you thought about Atlas? You can use an update progress control to
display some custom text/graphic whilst the Ajax post back is
completing.


(e-mail address removed) wrote:


I see :( Thanks bruce.
Apart animated gif, is there any simple solution I can use to entertain
the user during a long running task, possibly without spending a week
to implement it ? I have seen some of such nice animations, but I am
unsure about the technology they used.

-Pam

bruce barker (sqlwork.com) ha scritto:




this will not work. in the asp.net from processing model, a button
click
posts back, and the page is rebuilt and sent back to the browser.
this means
the brwser will not see the html to display the gif until all the
server
processing is done.

you can set the gif with client code, but in general animated gifs
will not
run during a postback. the best solution is start the long running
process
in a background thread, and poll for completion. google this
newgroup for
processing message, and you shoudl find examples.

-- bruce (sqlwork.com)




I am reposting hoping better luck :)

I can't achieve this simple thing: I have an animated gif in an image
control (ImageProgress1). The image visibility is set to false. I
want
that when the User click on a given button (ButtonSomeLongTask) to
execute a long task Me.ImageProgress1 become visible until the
task on
the server is finished. I call the task this way:

Protected Sub ButtonSomeLongTask_Click(ByVal sender As Object, ByVal
e As System.EventArgs) Handles ButtonSomeLongTast.Click
ExecuteLongTask() 'here there is a call to a web service
End Sub

Any *simple* example to do it?

-Pam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top