/// <summary> /// Handles the click event on the register button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRegister_ServerClick(object sender, System.EventArgs e) { if (Page.IsValid) { string nickName = HttpUtility.HtmlEncode(tbxNickName.Value); // check if the nickname is already taken. bool nickNameAlreadyExists = UserGuiHelper.CheckIfNickNameExists(nickName); if (nickNameAlreadyExists) { // already exists lblNickNameError.Visible = true; } else { // doesn't exist. Form is valid, so write the data into the database. DateTime?dateOfBirth = null; string emailAddress = string.Empty; bool emailAddressIsPublic = false; string iconURL = string.Empty; string ipNumber = string.Empty; string location = string.Empty; string occupation = string.Empty; string password = string.Empty; string signature = string.Empty; string website = string.Empty; bool autoSubscribeThreads = true; short defaultMessagesPerPage = 10; if (tbxDateOfBirth.Value.Length > 0) { try { dateOfBirth = System.DateTime.Parse(tbxDateOfBirth.Value, CultureInfo.InvariantCulture.DateTimeFormat); } catch (FormatException) { // format exception, date invalid, ignore, will resolve to the default : null } } emailAddress = tbxEmailAddress.Value; emailAddressIsPublic = !chkEmailAddressIsHidden.Checked; if (tbxIconURL.Value.Length > 0) { iconURL = tbxIconURL.Value; } ipNumber = lblIPNumber.Text; if (tbxLocation.Value.Length > 0) { location = tbxLocation.Value; } if (tbxOccupation.Value.Length > 0) { occupation = tbxOccupation.Value; } if (tbxSignature.Value.Length > 0) { signature = tbxSignature.Value; } if (tbxWebsite.Value.Length > 0) { website = tbxWebsite.Value; } //Preferences autoSubscribeThreads = chkAutoSubscribeToThread.Checked; if (tbxDefaultNumberOfMessagesPerPage.Value.Length > 0) { defaultMessagesPerPage = HnDGeneralUtils.TryConvertToShort(tbxDefaultNumberOfMessagesPerPage.Value); } // add it string mailTemplate = ApplicationAdapter.GetEmailTemplate(EmailTemplate.RegistrationReply); int userID = UserManager.RegisterNewUser(nickName, dateOfBirth, emailAddress, emailAddressIsPublic, iconURL, ipNumber, location, occupation, signature, website, mailTemplate, ApplicationAdapter.GetEmailData(), ApplicationAdapter.GetParserData(), autoSubscribeThreads, defaultMessagesPerPage); Response.Redirect("registrationsuccessful.aspx", true); } } }