Simple problem

S

Steven

Hello,
First, let me state that I am trying to learn asp.net, so I am a beginner.
Now on to the issue. I have a webform with a single Textbox and a
FileSystemWatcher monitoring a directory for OnCreate events. I am trying
to change the text in response to an OnCreate event. I would like to change
the Forecolor to red, from black. Apparently, this is not as easy to do as
in vb.net. I have tried the direct approach in the OnCreate event;
"Textbox1.Forecolor = Color.Red". This produces no results. I have tried
applying a style to the Textbox, no results. Server.Tranfer to another page
produces a "Object not set to an instance" error. Server.Transfer to the
same page does nothing. What do I need to do to accomplish this simple
task?

Thanks,
Steven
 
K

Kevin Spencer

Hi Steven,

I hope you'll pardon me if I only point you in the right direction.

An ASP.Net app is a client-server app, with HTTP as the transport between
client and server. HTTP is stateless, so the only communication between
client and server is via Requests from the client browser.

You have a FileSystemWatcher on the server, which is monitoring for events.
On the client, you have a disconnected web page and a browser. Can a
disconnected browser receive events on the server? No. So, how DO you
respond to server-side events in the client? Well, now it doesn't seem so
simple, does it?

First of all, the FileSystemWatcher raises an event whenever you tell it to
(OnCreate). This event fires asynchronously on the server. IOW, it can fire
at any time. The only time you can update the client from the server is when
you receive a Request from the client. The Request can come at any time. So,
how do we synchronise the server-side event to the client?

The answer is, we don't. We can't. What we CAN do is to create some
persistent server-side objects that remain across Requests, handle the
OnCreate event from the FileSystemWatcher, and maintains state until a fresh
Request comes in from the client. At that point (Request) we can update the
client.

Next question: How does the client know when to do a PostBack for getting
the update? Again, it doesn't. It can't. It's disconnected. So, what can you
do? You can set up a timing mechanism on the client that refreshes the page
(makes a fresh Request) at intervals. This can be done with JavaScript or a
META Refresh tag on the client.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
M

Marcus Monaghan

Stephen,

From what I can gather from the information you have provided you are
trying to change the background colour of the text box without reloading
the page. Web pages work on a pull technology, it needs to ask for new
information. I'd say you'll have to implement some kind of polling
mechanism where the page gets refreshed every so often.

I'm unfamiliar with the FileSystemWatcher and therefore don't know
whether you are monitoring a directory on the client or server machine?
If it's the client machine then you might be able to do something with
some [java-vb]script.

Regards,
Marcus
 
E

Eliyahu Goldin

Steven,

Putting FileSystemWatcher on a web form doesn't make much sense. A web form
lives very short time, from the moment when an http request arrives till the
moment when the http response is built and sent to the client. Could be less
than a second. Do you anticipate that your directory event will be fired in
the same time? Probably you need to re-think your design.

Eliyahu
 
S

Steven

First, thank you for your replies. I am building a demo where the user will
stay at the same page until the OnCreate event fires then navigate to
another page, then back to the original page with a new FileSystemWatcher.
The user can control when the OnCreate event is fired. All I am trying to
do is to relay to the user, in some way, that the OnCreate event has
occurred.
I am open to suggestions on how to do this.
 
K

Kevin Spencer

I am open to suggestions on how to do this.

Well, you already have mine. ;-)

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
E

Eliyahu Goldin

Steven,

Kevin's response is marvelous. Read it slowly and several times.

Eliyahu
 
S

Steven

Thanks again. I have looked at the Meta tag and that is what I would like
to do, but only postback once after the OnCreate event occurs. One
requirement is that the user must be able to navigate around an existing asp
and html website, which I have 'hung' the asp.net app from. I am thinking
that asp.net may not the correct technology solution. I'm not sure what
else to use though.
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top