using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
public partial class frm4_02 : System.Web.UI.Page
{
public int ExchAccID = 0;
protected void Page_Load(object sender, EventArgs e)
{
if(Request.QueryString["ID"] != null)
{
ExchAccID = Convert.ToInt32(Request.QueryString["ID"]);
if(!IsPostBack)
{
PopulateScreen(ExchAccID);
}
}
else
throw new Exception("Invalid Query String passed - Needs Exchange Accounts ID.");
}
private void PopulateScreen(int ID)
{
ExchangeAccounts ea = new ExchangeAccounts();
OleDbConnection cn = null;
try
{
ClearScreen();
if(ea.GetRecord(ID, ref cn))
{
txtEmailAddress.Text = ea.EmailAddress;
txtFirstName.Text = ea.FirstName;
txtSurname.Text = ea.Surname;
cboUserType.SelectedValue = Convert.ToString(ea.UserStatus);
txtPassword.Text = ea.Password;
}
}
catch(Exception ex)
{
Common.PEH("PopulateScreen", "frm4-02", ex.Message);
}
}
private void ClearScreen()
{
try
{
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 = "";
System.Threading.Thread.Sleep(500);
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;
}
catch(Exception ex)
{
Common.PEH("PopulateScreen", "frm4-02", ex.Message);
}
}
private bool GetScreenData(ref ExchangeAccounts ea)
{
try
{
ea.EmailAddress = txtEmailAddress.Text;
ea.FirstName = txtFirstName.Text;
ea.Surname = txtSurname.Text;
ea.UserStatus = Convert.ToInt32(cboUserType.SelectedValue);
if(txtPassword.Text != "")
ea.Password = txtPassword.Text;
else
{
string script = "window.onload = function(){ alert('";
script += "Blank Password is not allowed, please try again.";
script += "')};";
ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
return false;
}
return true;
}
catch(Exception ex)
{
Common.PEH("GetScreenData", "frm4-02", ex.Message);
return false;
}
}
protected void imgButtClear_Click(object sender, ImageClickEventArgs e)
{
txtEmailAddress.Text = "";
}
private bool SaveExchangeAccount()
{
ExchangeAccounts ea = new ExchangeAccounts();
OleDbConnection cn = null;
try
{
if(ExchAccID != 0)
{
if(ValidateScreenData())
{
//We are modifying an existing record so get existing data into ea and then
//update the few fields we are editing here to their on screen changes.
if(ea.GetRecord(ExchAccID, ref cn))
if(GetScreenData(ref ea))
ea.AddRecord(ExchAccID, true, ref cn);
} //If screen not validated then we don't proceed to amend record.
}
PopulateScreen(ExchAccID);
return true;
}
catch(Exception ex)
{
Common.PEH("SaveExchangeAccount", "frm4-02", ex.Message);
return false;
}
}
/// <summary>
/// Validates that none of the screen items that are text are left blank and also
/// that the drop down lost has something other than Nothing Selected.
/// </summary>
/// <returns>True if screen is Valid, False if not.</returns>
private bool ValidateScreenData()
{
string strStartText = "Unable to save changes for the following reasons: \\n";
string strText = "";
try
{
if(txtEmailAddress.Text == "")
strText += "\\nEmail Address is not completed, ";
if(txtFirstName.Text == "")
strText += "\\nFirst Name is not completed, ";
if(txtSurname.Text == "")
strText += "\\nSurname is not completed, ";
if(cboUserType.SelectedValue == "0")
strText += "\\nUser Type is not completed. ";
if(txtPassword.Text == "")
strText += "\\nPassword is not completed. ";
if(strText != "")
{
string script = "window.onload = function(){ alert('";
script += strStartText;
script += strText;
script += "')};";
ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
return false;
}
else
return true;
}
catch(Exception ex)
{
Common.PEH("ValidateScreenData", "frm4-02", ex.Message);
return false;
}
}
protected void Save_Click(object sender, ImageClickEventArgs e)
{
string message = "";
try
{
if(SaveExchangeAccount())
{
message = "Information saved successfully.";
}
else
{
message = "Information NOT saved.\\nPlease correct and try again.";
}
string script = "window.onload = function(){ alert('";
script += message;
script += "')};";
ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
}
catch(Exception ex)
{
Common.PEH("SaveExchangeAccount", "frm4-02", ex.Message);
}
}
}
<script type="text/javascript">
function sbc(OnOrOff) {
if (OnOrOff)
{
var v = document.getElementById("<%=txtEmailAddress.ClientID%>");
v.style.backgroundColor = "PowderBlue";
var v = document.getElementById("<%=txtFirstName.ClientID%>");
v.style.backgroundColor = "PowderBlue";
var v = document.getElementById("<%=txtSurname.ClientID%>");
v.style.backgroundColor = "PowderBlue";
var v = document.getElementById("<%=txtPassword.ClientID%>");
v.style.backgroundColor = "PowderBlue";
}
else
{
var v = document.getElementById("<%=txtEmailAddress.ClientID%>");
v.style.backgroundColor = "White";
var v = document.getElementById("<%=txtFirstName.ClientID%>");
v.style.backgroundColor = "White";
var v = document.getElementById("<%=txtSurname.ClientID%>");
v.style.backgroundColor = "White";
var v = document.getElementById("<%=txtPassword.ClientID%>");
v.style.backgroundColor = "White";
}
}
</script>
<asp:ImageButton ID="Save" runat="server" src="images/icon-save.png" OnClientClick="javascript:sbc(true);" OnClick="Save_Click" />
protected void Save_Click(object sender, ImageClickEventArgs e)
{
string message = "";
try
{
if(SaveExchangeAccount())
{
ClientScript.RegisterStartupScript(this.GetType(), "sbcCall", "sbc(false);", true);
}
else
{
message = "Information NOT saved.\\nPlease correct and try again.";
string script = "window.onload = function(){ alert('";
script += message;
script += "')};";
ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
}
}
catch(Exception ex)
{
Common.PEH("Save_Click", "frm4-02", ex.Message);
}
}
What you will have to do is employ Javascript code (or possibly CSS3 transitions) that manipulates your elements on the page. This all happens client-side; your C# won't have anything to do with this. You can use the JQuery library to help ease some of the code writing if you go the Javasript route.