ASP.NET - How to flash the background of text boxes after saving to indicate something happened.
Posted on 2016-09-08
I am working on an asp.net project using c# as the language used and want to emulate what I have always done in desktop applications which is when a user saves a record and the save is successful, I clear the text boxes of input, flash the background colour of the cleaned boxes to a non-white (usually use Powder Blue or a similar pale colour) and then reload the saved data to show that the information has been stored successfully. Then return the BackColor to white again.
With web pages I would like to do the same thing but without generating masses of web traffic, so maybe there is a neat way of doing that?
At the moment I am saving the record then calling my PopulateScreen routine that does a call to my ClearScreen routine and then populates the text boxes from the database again. My ClearScreen routine looks like this:
private void ClearScreen()
txtEmailAddress.BackColor = System.Drawing.Color.PowderBlue;
txtFirstName.BackColor = System.Drawing.Color.PowderBlue;
txtSurname.BackColor = System.Drawing.Color.PowderBlue;
cboUserType.BackColor = System.Drawing.Color.PowderBlue;
txtPassword.BackColor = System.Drawing.Color.PowderBlue;
txtEmailAddress.Text = "";
txtFirstName.Text = "";
txtSurname.Text = "";
cboUserType.SelectedValue = "0"; //First entry in list
txtPassword.Text = "";
txtEmailAddress.BackColor = System.Drawing.Color.White;
txtFirstName.BackColor = System.Drawing.Color.White;
txtSurname.BackColor = System.Drawing.Color.White;
cboUserType.BackColor = System.Drawing.Color.White;
txtPassword.BackColor = System.Drawing.Color.White;
Common.PEH("PopulateScreen", "frm4-02", ex.Message);
When I run this I don't see the BackColor change it's as if the half second delay doesn't do anything, as I don't see the BackColor go blue and I am concerned that using Thread.Sleep is probably a ham fisted way of doing it.
I have found ways of throwing up an alert box confirming that the record is saved, but I'd rather not force the user to have to click the dialog every time they save.
Any help with this appreciated.