How to handle personalized events of a class in a web form?

  • Thread starter Thread starter Roberto López
  • Start date Start date
R

Roberto López

Hello,
I´m trying to do a progress page that indicates some visual information to
the user in a long directory copy process. I have a Class that copys
directories from one location to other. The function "CopyDirectory" is
started in a new Thread. This class also contains one Event that is raised
every directory is copied.
On my page I have declared an instance of my class with the "WithEvents"
modifier and i have writed an event handler for the class event into the
page. Every time the event is raised I change the text property of a textbox
in the page but it not shows because the page not refresh the textbox value.
I don´t know if it is possible to do this in a Web page. (I think In windows
forms it may be run).
Any suggestions will be apreciated.

Thanks.

Roberto López
 
The problem is that only the page can request a refresh of itself. You
can't do it from the server side.
You can have the browser refresh the status by putting an HTML line like
this in your code:
<META HTTP-EQUIV="refresh" CONTENT="3">
That will cause the browser to refresh every 3 seconds (and you can check
the status of the operation each time and redirect to a "done" page when
appropriate.)
Here's more details:
http://www.fawcette.com/vsm/2002_11/magazine/features/chester/
http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=547

Another option is that you could call a web service from your client side
JScript. Use the web service behavior for this. (WebService.htc) This
technique works with IE only.
Here's more details:
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/behaviors/overview.asp

http://msdn.microsoft.com/downloads...rnet/behaviors/library/webservice/default.asp
 
Because of the disconnected stateless nature of a web application I don't
this approach will work.. Here's what I'm guesing is happening..
Your page is recieving the events as they are raised by your class declared
WithEvents but the page is only rendered once after the last event fired
(synchronous execution, meaning the page is not rendered until all the
processing is done) so your TextBox has the last directory that was copied
written to its text property...To verify this set a breakpoint in your event
handler and see if you are hitting that breakpoint...
 
Hi,
And it´s possible to implement something function like AutoPostBack. Eg. the
option button control like the dropdownlist control has a property
"AutoPostBack" that do a page postback when the control changed. How can I
implement something like this to post bak the page when the clas event is
raised.
 
It´s really good explained,

Thanks a lot.


alien2_51 said:
The client has to generate the postback, the client has no knowledge of
anything your doing on the server... It has no knowledge of your class that
is responding to events.. In fact, while your page class is bieng processed
and is responding to events that are bieng raised the client hasn't even
been issued a response yet.. So your still at the server you don't have a
page or any controls to autopostback from... If you want to use a progress
bar build a windows application... or embed a rich control on your page that
can run its process on the client.. The type of syncronization required for
a progress bar is not available in a traditional web application that uses
ASP.NET controls...

HTH


information
 
Back
Top