JavaScript for OnTextChanged event.

A

Alex Nitulescu

Hi.

I have created a web-based file manager. Now I'd like to watch a folder for
changes, and when a change occurs I'd like to refresh my page.
Okay. So I have created a FileSystemWatcher set on the folder I need to
watch. It works fine. The problem occurs when I need to trigger an automatic
Refresh.
So I added two handlers - OnChanged and OnRename, in the same class as my
filemanager.

In the handlers I tried to say Response.redirect(mypage) to force the
refresh, but the error I got was: "Cannot redirect after HTTP headers have
been sent."

So I tried to change the text of some textbox instead
<asp:textbox id="txtFileSystemWatcher"
OnTextChanged="javascript:RefreshPage();" Visible=true Width=500
Runat=server></asp:textbox>

with this handler:
Private Sub OnChanged(ByVal source As Object, ByVal e As
FileSystemEventArgs)
txtFileSystemWatcher.Text = "FileSystemWatcher: " & "File: " &
e.FullPath & " " & e.ChangeType
End Sub

and add an OnTextChanged client-side event-handler which looks like this:

function RefreshPage() {
__doPostBack('txtFileSystemWatcher', '');
}

which would force the refresh. However, now I have the following error:
BC30456: 'javascript' is not a member of 'ASP.BrowseFiles_aspx'.

So I changed the HTML to
<asp:textbox id="txtFileSystemWatcher" OnTextChanged="RefreshPage()"
Visible=true Width=500 Runat=server></asp:textbox>
and now, sure enough, I get
BC30456: 'RefreshPage' is not a member of 'ASP.BrowseFiles_aspx'.

I also tried in OnLoad of the page to register the event with
txtFileSystemWatcher.Attributes.Add("OnTextChanged",
"javascript:RefreshPage()")
and
txtFileSystemWatcher.Attributes.Add("OnTextChanged", "RefreshPage()")

but it still does not work.

What am I missing here, please ?

Thank you, Alex
 
W

Wilco Bauwer

1. Don't write stuff like '__doPostBack' yourself, ever. Use
Page.GetPostBackEventReference instead if you want to get the postback
function call.
2. Why not set your textbox's AutoPostBack to true? In that case the
textbox control will render an onchange client-side eventhandler, which
will postback if the text was changed.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top