Best way to save status of dynamic web interface - ui-design

Basically in my website I have a sidebar with a stack of boxes; each box can be collapsed or expanded by the user. I need to save the status of each box for the currently logged in user.
I don't want to use cookies because if an user changes browser or computer, all the boxes will go to the default status.
Should I save this information on the database making a query every time the user collapses/expands a box? How would you handle this? Thanks.
Edit: What if an user clicks on the toggle button repeatedly, like ten times in two seconds, just because he enjoys the boxes' animation? He will make ten queries in two seconds. So maybe the question should be: when should I save this data?

Call a (client-side) "changed" function every time a box changes.
Keep two items of (client-side) state: the time the last update to the server was sent and whether a timer has been set.
Write a (client-side) "update" function that sends the update and updates the state to mark that the last update was just now.
When the changed function is called: if a timer is set, then return immediately; if an update has never been sent or the last update was sent more than ten seconds ago, then call the update function and return. Otherwise set a timer to send the update after ten seconds.
The timer callback should simply clear the timer flag and call the update function.
Also on an unload event check if a timer was set and if it was then clear the timer and call the timer callback function.
So the result is that you send the update immediately except when the user is flapping, in which case you only send an update every ten seconds at most.
There might be some cases where you lose an update, but this is likely to only happen if the user was playing with the toggling and then closed the page before the timer fired, in which case he probably won't notice anyway.

If you need to persist these options from multiple computers you will need some form of server side storage.
This could be database or flat file. The choice depends on what you have available, skill set, and the need to scale. If you are going to have just a few users, a flat file may be your best choice.

Related

Allowing User to Select off of Partial Records in a Continuous Form in Access

I am creating a form in access to allow users to input multiple production records for a day.
The form is set as a continuous data entry form and has data validation in place to ensure the information being entered is consistent.
I am having a problem where if a user starts typing something on a new entry, they essentially have no way to back out of it or cancel the entry without completely filling out the form.
I want to keep the data validation to ensure the data being recorded is accurate, but also do not want to lock users into an entry unless it is completely filled out.
I think the ideal would be to allow users to create a new record or select other records without needing to save the current record.
If it would be possible to make it so records only save when a button at the top of the form is pressed I think that would be ideal, but I have not found a good way to do this without requiring it on every single entry.
I have attached a picture of what I am talking about, there could be various error messages but essentially if you try to click off when a record is incomplete it will give an error until the entire form is filled out.
Example of Error Message and Image of Continuous Form
'deselect' without saving but still save what had been entered up to
that point.
That you can simulate by setting the DefaultValue of each control in the AfterUpdate event of each control:
Me!SomeTextBox.DefaultValue = Nz(Me!SomeTextBox.Value)
However, I'm not sure that will be a good idea. And you may have to reset the default values when opening the form.

Store textbox changes in database

I want to store the values of multiple editable text-boxes in my database. The user can edit them all the time and my question is when to save them? If I execute a SQL statement every time the content changes (in the onchange event) there is too much traffic on the database, isn't it?
Is there any better solution?
I'd like to do it without a save button.
You can send the changes periodically (e.g. every 5 seconds), and try sending any unsaved changes upon leaving the page (beforeunload event):
window.addEventListener("beforeunload", function () {
/* Check for changes and send anything unsaved. */
});

How To Correctly Display A Dialog Box During Long Processing - VB.NET

Running into a situation when user searches for orders of customer for past 4 years. As the DB query takes a long time, I want to show a pop up box just stating 'please wait. quering for results'. so when they start their search I want to show the message box until the results are obtainned and at that point I want to close the message box.
My current way, I know is incorrect as the pop up box locks up and states (not responding).
Would using a background worker be an over kill, or should I go with a progress bar?
My current way:
Dim frmProcessing As New ShowWaitForm
'/ set location to open the form
'/ set any custom message
frmProcessing.Show()
'//do db query and other stuff with result-> i CANNOT CHANGE THIS CALL NOR CAN I MODIFY HOW IT IS CALLED/FUNCTIONS
frmProcessing.Close()
frmProcessing = Nothing
I personally find the background worker to be a better choice most of the time. It allows me some more flexibility later if I want to add more information. I can use the ProgressChanged event to update a progress bar, and later if my needs change I can do other things as well.

How to disable button on other pc

I have developed a Windows application using C# 4 and SQL Server 2008,
My application works very well.
This application is using by six users at the same time.
I want that, whoever click button first from these six users, the button on other 5 user's PC must be disable till the user finishes adding data.. then it must be enabled...
something..
btn.disable = true;
data saved
btn.disable = false;
so, it cant be duplicated..
You need set a flag someone on your data to indicate that a record is being edited. Then when the user attempts to edit the same record it first checks to see if the edit flag is set and if so then reports "You can't edit this record because someone is already editing it".
Disabling a button automatically will probably be very inefficient as you will have to constantly check to see if a record is being edited.
That said it could be done using a timer to continually check the database.

ASP.NET Keep fileupload after postback

I'm writing an intranet ASP.NET page using VB.NET. I've run into a particularly nasty problem dealing with handling file uploads. I'll do my best to explain the problem, and perhaps someone can help.
My problem is almost a duplicate of this one, or this one, except (other than the filename) I don't care about sending the file to the server until the other data has been reviewed.
Here's the situation:
Joe Q. Dataentry inputs some data into several fields. The first 3 are drop down, and when he changes the selection, a postback event is fired that queries a database for valid entries for the other drop down selections. After selecting the values, he inputs some other data, chooses a file to accompany the data and clicks the "Update" button. When he hits the button, it fires a postback event that sends the current data to the server to be validated. The data will create a change in the database, so he is presented with a view of the current state, and what it will look like when his changes are made. He can now either confirm or cancel the operation for whatever reason.
Part of the data he will see involves the extension of the file which may be a PDF, or could also be some image file or other document.
Now here's where my problem is - on each postback event, the fileupload dialog is cleared. I was getting around it by creating a temporary file on the first postback and then renaming if he clicks OK or deleting on Cancel... but I need to do a variety of things, based on the previous state of data and the filename. I've tried to keep some session variables to retain the filename, and that works OK for just renaming the file, but for what I need to do it gets unwieldy.
What I want to do is be able to have the postback event to present the changes, and then when the user clicks "OK", submit the file. Is there any possible way to do that?
One of my thoughts was to do some of the validation client-side (I'm already re-validating server side so I'm not too worried about data security there), but I don't know how I could get the information from the database query.
Thanks for any help, and reading my slightly convoluted story/situation!
EDIT:
It appears that what I want to do is prevent a certain button from firing a full postback. Is there any way to do that?
EDIT II:
I have an update panel on the page already - is there any way for the button to only post what's in the update panel?
What you might want to do is place your drop-downs inside of an ASP.NET AJAX UpdatePanel, and keep your file upload control out of that.
Your update panel will do the post backs and allow your validation logic to happen without submitting the file, then when you hit your final "Save" button (which is also outside of your UpdatePanel) the entire form will be submitted back and you can work with your file then.