Results 1 to 14 of 14

Thread: AutoSave Timer

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2024
    Posts
    3

    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.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,518

    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

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,840

    Re: VS2019 - Timer

    Quote Originally Posted by rtancer View Post
    I was thinking I could use the Timer function.
    So what happened when you tried that?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,840

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,826

    Re: VS2019 - Timer

    Quote Originally Posted by rtancer View Post
    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

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,840

    Re: VS2019 - Timer

    Quote Originally Posted by Zvoni View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2024
    Posts
    3

    Re: VS2019 - Timer

    Quote Originally Posted by jmcilhinney View Post
    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.

  8. #8
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,826

    Re: VS2019 - Timer

    Quote Originally Posted by jmcilhinney View Post
    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

  9. #9
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,288

    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??

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,840

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,703

    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
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  12. #12
    Hyperactive Member
    Join Date
    Jul 2022
    Posts
    424

    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

  13. #13

    Thread Starter
    New Member
    Join Date
    Oct 2024
    Posts
    3

    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.

  14. #14
    Hyperactive Member
    Join Date
    Jul 2022
    Posts
    424

    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
  •  



Click Here to Expand Forum to Full Width