-
Oct 16th, 2024, 02:48 PM
#1
Thread Starter
New Member
AutoSave Timer
I need to have data entered in a page on a web app automatically save the data. How can I do this? I was thinking I could use the Timer function. I need it to execute my code that runs a stored procedure to update the data.
-
Oct 16th, 2024, 04:49 PM
#2
Re: VS2019 - Timer
I'm unclear as to what role you play in this. Is this your web app and you want to periodically post the data back to the server, or are you watching for changes on a web app, or something else?
My usual boring signature: Nothing
-
Oct 17th, 2024, 05:46 AM
#3
Re: VS2019 - Timer
Originally Posted by rtancer
I was thinking I could use the Timer function.
So what happened when you tried that?
-
Oct 17th, 2024, 05:52 AM
#4
Re: VS2019 - Timer
What's the actual point here? Maybe you could provide a FULL and CLEAR explanation of what you're trying to achieve. If the user is entering the data, why can't they click a button? If you want the data saved each time they change a field, you should be looking at the appropriate event(s) that occur on those changes. Regardless of any of that, this sounds like a JavaScript problem rather than a VB.NET problem, but we can't know for sure based on such a vague description.
-
Oct 17th, 2024, 06:37 AM
#5
Re: VS2019 - Timer
Originally Posted by rtancer
I need to have data entered in a page on a web app automatically save the data. How can I do this? I was thinking I could use the Timer function. I need it to execute my code that runs a stored procedure to update the data.
What utter nonsense to use a Timer.
It doesn't matter if it's a Web App, Desktop App or whatever else:
If User Input has to be saved somewhere, then Timer is the worst approach, because i enter all Data within 1 minute, whereas my mother, who is 75 years old, needs 10 Minutes.
So, will your Timer then save my data correctly, while the data my mother entered gets only saved half?
use Events (like exiting an Edit-Field) to make your plausibilty-checks, and if everything is OK, trigger the save routine.
OTOH, if you want to implement something like an "AutoSave"-Feature (like we have here on vbforums), that's a different kettle of fish.
That's the only reason to use a Timer
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Oct 17th, 2024, 07:22 AM
#6
Re: VS2019 - Timer
Originally Posted by Zvoni
OTOH, if you want to implement something like an "AutoSave"-Feature (like we have here on vbforums), that's a different kettle of fish.
That's the only reason to use a Timer
That's what I was thinking this might be, but it would be better if the problem were explained fully and clearly rather than our guessing.
-
Oct 17th, 2024, 08:04 AM
#7
Thread Starter
New Member
Re: VS2019 - Timer
Originally Posted by jmcilhinney
That's what I was thinking this might be, but it would be better if the problem were explained fully and clearly rather than our guessing.
This is exactly what I am looking for - an AutoSave function. I have a web app on our intranet, and I have a Save button for the user to save what they have entered. However, upper management wants me to implement an autosave, so if someone does not click on the save button, the system does it automatically every minute or so.
-
Oct 17th, 2024, 08:05 AM
#8
Re: VS2019 - Timer
Originally Posted by jmcilhinney
That's what I was thinking this might be, but it would be better if the problem were explained fully and clearly rather than our guessing.
Agreed.
My skills in Divination are a bit rusty...
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Oct 17th, 2024, 11:58 AM
#9
Re: VS2019 - Timer
There are ways to Auto Save data without using a timer. As Zvoni mentioned you can use events such the "Leave" event of a control or the "FormClosing" event of a form. What if the user doesn't want to keep the data they entered??
-
Oct 17th, 2024, 08:31 PM
#10
Re: VS2019 - Timer
If you want to do something every minute, rather than when some specific action is taken by the user, then a timer is the right way to do it. If you want to perform the same action as when the user clicks a button, you need to invoke the same function when the timer expires.
This thread is about ASP.NET, so I'm moving it there. What type of web app this is matters to, but you haven't told us that. If it's Web Forms, I believe that there is a Timer server control, so that's the obvious option. If it's something else, e.g. MVC, then you will be using a JavaScript timer, which is very different. Again, you need to provide a FULL and CLEAR explanation of the problem.
-
Oct 18th, 2024, 06:08 AM
#11
Re: AutoSave Timer
If it is for web then what I was thinking was to implement a timer with JavaScript or Ajax and pass , post, it to your server.
I wouldn't never touch a native asp.net timer server control and I avoided it like the plague when I was web developing as it gives those terrible postbacks.
Maybe this can help
https://stackoverflow.com/questions/...timer/25233233
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Oct 18th, 2024, 06:33 AM
#12
Hyperactive Member
Re: AutoSave Timer
Back in the day (2012) I used JavaScript to have a timer that would auto save the data entered into a asp.net web page and "lock" the page (just hid it behind a div)
I'd guess there are better ways to go about it, but it may give you a start.
Code:
<!--
var start=new Date();
start=Date.parse(start)/1000;
var counts=300; // 1800 number of seconds til automatic logoff
function CountDown(){
var now=new Date();
var day=now.getDate();
if (day < 10) {day='0'+day};
var month=now.getMonth()+1;
var year=now.getFullYear();
var hour=now.getHours();
var minutes=now.getMinutes();
if (minutes < 10) {minutes='0'+minutes};
var seconds=now.getSeconds();
if (seconds < 10) {seconds='0'+seconds};
var DisplayDate=month + '/' + day + '/' + year + ' ' + hour + ':' + minutes + ':' + seconds
now=Date.parse(now)/1000;
var x=parseInt(counts-(now-start),10);
var y=parseInt(x/60,10);
var z=parseInt(x%60,10);
if (z>9) {
document.getElementById('lblTimeout').innerHTML = '<div id="timeout" align="center">Session Lock in ' + y + ':' + z + '<br>' + DisplayDate + '</div>'
}
else {
document.getElementById('lblTimeout').innerHTML = '<div id="timeout" align="center">Session Lock in ' + y + ':0' + z + '<br>' + DisplayDate + '</div>'
}
if(x>0){timerID=setTimeout("CountDown()", 500)}
else{
try {
if (document.getElementById('lblCurrentTab').innerHTML=='ProgressNote' && document.getElementById('txtProgressNoteMode').value!='') {
//if the user was in progress notes and their session locked down, check for a PN edit/new in progress. Instead of leaving it at the place they were
// force a save as draft to allow others to edit it
try {
var d = document;
var f = d.frames ? d.frames['DATACONTENT'] : d.getElementById('DATACONTENT');
var p = f.document || f.contentWindow.document;
p.getElementById('txthOkToCache').value='NO';
p.getElementById('btnSaveDraft').click();
p.getElementById('txtMode').value='';
d.all('txtProgressNoteMode').value='';
d.all.item('lblUserMessage').innerHTML='';
}
catch(e) {
alert('encountered an error : ' + e.description);
}
}
}
catch(e) {
alert('Portal was unable to auto-save before session lock due to : ' + e.description);
}
document.all('lblVisor').style.height=screen.height-50;
document.all('lblVisor').style.width=screen.width-15;
document.all('lblVisor').style.visibility="visible";
var VisorText;
var fWidth=screen.width-15;
var fHeight=screen.height-50;
VisorText='<IFRAME SRC="sessionlocked.htm" WIDTH=' + fWidth + ' HEIGHT=' + fHeight + '></IFRAME>';
document.all('lblVisor').innerHTML=VisorText;
if (PortalHasFocus==true) {
window.open('SessionLocked.aspx','SessionLocked', 'resizeable=0,status=0,left=10,top=10,toolbar=0,location=0,directories=0,scrollbars=0,width=350,height=200');
void('');
}
}
}
window.setTimeout('CountDown()',500);
function DisplayDataRequestMessage()
{
document.all.item("lblUserMessage").innerText = 'Requesting data from server';
}
function DontShowMenu() {
return false }
-->
don't know why the editor is adding so many tabs
-
Oct 21st, 2024, 07:31 AM
#13
Thread Starter
New Member
Re: VS2019 - Timer
I am sorry for not giving a clear description. I am using Web Forms. I guess it does belong on asp.net forum.
-
Oct 21st, 2024, 08:00 AM
#14
Hyperactive Member
Re: AutoSave Timer
I used web forms in this project as well, but I used JavaScript to handle the timer stuff at the client side. This was created in VS 2003 in 2004, that was in use until 2013.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|