protected void Page_Load(object sender, EventArgs e) { //Deactivate button after sucessful click btnRegister.Attributes.Add("onclick", " this.disabled = true; " + ClientScript.GetPostBackEventReference(btnRegister, null) + ";"); string schoolUserName = Session["userName"] as string; string schoolPassword = Session["password"] as string; loginForm.Visible = true; registered.Visible = false; //Force loguout if session variables are not found if (String.IsNullOrEmpty(schoolUserName)) { FormsAuthentication.SignOut(); Response.Redirect("/Account/Login.aspx"); } else if (String.IsNullOrEmpty(schoolPassword)) { FormsAuthentication.SignOut(); Response.Redirect("/Account/Login.aspx"); } else { SchoolUserName.Text = schoolUserName; } //Fill dropdown lists from Database Query if (!this.IsPostBack) { string SQLConnection = ConfigurationManager.ConnectionStrings["SQLConnection"].ConnectionString; using (SqlConnection con = new SqlConnection(SQLConnection)) { //Get hardwareType for dropdown list using (SqlCommand cmd = new SqlCommand("SELECT hardwareType FROM hardwareType ORDER BY CASE WHEN hardwareType = 'Other' THEN 1 ELSE 0 END, hardwareType")) { cmd.CommandType = CommandType.Text; cmd.Connection = con; con.Open(); DeviceType.DataSource = cmd.ExecuteReader(); DeviceType.DataTextField = "hardwareType"; DeviceType.DataValueField = "hardwareType"; DeviceType.DataBind(); con.Close(); } //Get OSType for dropdown list using (SqlCommand cmd = new SqlCommand("SELECT OSType FROM OSType ORDER BY CASE WHEN OSType = 'Other' THEN 1 ELSE 0 END, OSType")) { cmd.CommandType = CommandType.Text; cmd.Connection = con; con.Open(); OSType.DataSource = cmd.ExecuteReader(); OSType.DataTextField = "OSType"; OSType.DataValueField = "OSType"; OSType.DataBind(); con.Close(); } //Get OSType for dropdown list using (SqlCommand cmd = new SqlCommand("SELECT house FROM houses ORDER BY CASE WHEN house = 'N/A (Staff)' THEN 1 ELSE 0 END, house")) { cmd.CommandType = CommandType.Text; cmd.Connection = con; con.Open(); House.DataSource = cmd.ExecuteReader(); House.DataTextField = "house"; House.DataValueField = "house"; House.DataBind(); con.Close(); } } //Set dropdown defaults DeviceType.Items.Insert(0, new ListItem("--Select Hardware Type--", "0")); OSType.Items.Insert(0, new ListItem("--Select OS Type--", "0")); House.Items.Insert(0, new ListItem("--Select House--", "0")); } }