Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Forcing a refresh
#1
with Intraweb I have a timer which checks every minute to see if the data the user is viewing has changed and a page refresh is required. What code should I use to trigger the refresh. I understand that a component on the form can have its click event executed, but how is that done. I have seen some ideas about WebApplication.CallBackResponse.AddJavaScriptToExecuteAsCDATA but not sure how to use it. Help will be appreciated.
Reply
#2
To force a full page refresh (reload) you can call from your OnAsyncTimer event AsyncReload.

Code:
procedure TDlgMain.IWTimer1AsyncTimer(Sender: TObject; EventParams: TStringList);
begin
  AsyncReload;
end;

On the other hand if you change a property of a IWControl, the state is automaticly synced to the webbrowser. No manual refresh is needed.
Reply
#3
(12-13-2022, 08:57 PM)jeroen.rottink Wrote: To force a full page refresh (reload) you can call from your OnAsyncTimer event AsyncReload.

Code:
procedure TDlgMain.IWTimer1AsyncTimer(Sender: TObject; EventParams: TStringList);
begin
  AsyncReload;
end;

On the other hand if you change a property of a IWControl, the state is automaticly synced to the webbrowser. No manual refresh is needed.
Many thanks for your good advice, the AsyncReload works just fine. I have a couple more questions (1) could I have found this out in some documentation somewhere? and (2) when the AsyncReload is actioned, it does not activate any of my delphi code which created the page (mostly centred around a Grid). I was trying to set a TDateTime to record when the reload happened, so that unnecessary reloads would not occur, but the code was not actioned. How is the AsyncReload able to refresh the page without re-actioning the code that originally created it?
Reply
#4
1) Doc's are scattered and not up-to-date. I get most info from the source (hope you have access to it), the demo's on Github and this forum. At the end it comes to html, javascript and css. There is plenty info on the internet without the Intraweb specifics. That's the way I performed a refesh in the past.  window.location.reload(true);
In Intraweb this is written as WebApplication.CallBackResponse.AddJavaScriptToExecuteAsCDATA('window.location.reload(true);');
And that is the implementation of TIWForm.AsyncReload!

2) Not sure what you excactly mean. Do you mean the statements that are in your page's constructor? Those are only called once on TIWForm object creation. TIWForm.OnRender is called on rendering the page. But I am not sure if that is what you are after.
Can't you create a method to fill the grid and call it from the IWTimer1AsyncTimer eventhandler?
By updating the grid, Intraweb invalidates the grid-control and automaticly renders the new contents in the browser. No need for a AsyncReload() in that case.
Reply
#5
To trigger a page refresh in Intraweb, you can use the following code in the timer's OnTimer event:

delphi
Copy code
WebApplication.CallBackResponse.AddJavaScriptToExecute('location.reload();');
This code will execute the JavaScript location.reload() function, which refreshes the current page.

Alternatively, you can use the WebApplication.Synchronize method to execute the refresh code on the main thread:

delphi
Copy code
WebApplication.Synchronize(procedure begin
  WebApplication.ShowMessage('Refreshing page...');
  WebApplication.UpdateSession;
end);
This code displays a message to the user, updates the session state, and refreshes the page.

In both cases, the code should be placed in the timer's OnTimer event, which is triggered every minute to check if the data has changed and requires a page refresh. bluey
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)