protected void Page_Load(object sender, EventArgs e) { int page; bool result = int.TryParse(Request.QueryString["page"], out page); if (result) { pageNumber = page; } int startIndex = pageNumber * postsPerPage + 1; List <NewsPost> newsPosts = DatabaseHandler.GetNewsPosts(startIndex, startIndex + postsPerPage); if (newsPosts.Count > 0) { User sessionUser = Help.GetUserSession(Session); int pageCount = postsPerPage; if (pageCount > newsPosts.Count) { pageCount = newsPosts.Count; } for (int i = 0; i < pageCount; i++) { LiteralControl control = new LiteralControl(); control.Text = newsPosts[i].Data; Panel resultPanel = CreateNewsPanel(""); //resultPanel.Style["Position"] = "Absolute"; resultPanel.Controls.AddAt(0, control); resultPanel.Attributes.Add("style", "border:solid 1px black;"); resultPanel.BackColor = System.Drawing.Color.LightGray; resultPanel.Controls.AddAt(1, new LiteralControl("<br /> <br />")); //Creating the panel that contains the date. Panel infoPanel = new Panel(); Label creatorDateLabel = new Label(); creatorDateLabel.Text = "Created by: " + newsPosts[i].Creator.Username.ToLower() + " on " + newsPosts[i].Date; if (newsPosts[i].HasBeenUpdated) { creatorDateLabel.Text += " last updated on: " + newsPosts[i].LastUpdateDate; } infoPanel.Controls.Add(creatorDateLabel); infoPanel.HorizontalAlign = HorizontalAlign.Right; if (sessionUser != null && sessionUser.ID == newsPosts[i].Creator.ID) //If the creator and this user have the same ID then... { Button editButton = new Button(); editButton.Text = "Edit"; editButton.Command += EditButton_Command; editButton.CommandArgument = newsPosts[i].ID.ToString(); infoPanel.Controls.Add(editButton); } resultPanel.Controls.Add(infoPanel); Panel_News.Controls.AddAt(0, resultPanel); Panel_News.Controls.AddAt(1, new LiteralControl("<br /> <br />")); } Panel nextPanel = new Panel(); nextPanel.HorizontalAlign = HorizontalAlign.Right; if (pageNumber > 0) { Button backButton = new Button(); backButton.Command += BackButton_Command; backButton.Text = "Back"; nextPanel.Controls.Add(backButton); } if (newsPosts.Count > postsPerPage) { Button nextButton = new Button(); nextButton.Command += NextButton_Command; nextButton.Text = "Next"; nextPanel.Controls.Add(nextButton); } Panel_News.Controls.Add(nextPanel); } }
protected void CreateUserWizard_CreatingUser(object sender, LoginCancelEventArgs e) { e.Cancel = true; if (CreateUserWizard.UserName.Contains('%')) { Label_ErrorMessage.Text = "Username cannot contain %"; Label_ErrorMessage.Visible = true; } else { //Email verification: if (IsValidEmail(CreateUserWizard.Email)) { string ipAddress = Request.UserHostAddress; bool addUserResult = DatabaseHandler.AddUser(ipAddress, new User(0, CreateUserWizard.UserName, CreateUserWizard.Email, CreateUserWizard.Question, 0), CreateUserWizard.Password, CreateUserWizard.Answer); if (addUserResult) { string code = TextBox1.Text.Trim(); UserCodeError codeError; bool result = DatabaseHandler.DeactivateUserCode(CreateUserWizard.UserName, code, out codeError); if (result) { Label_UserCreated.Visible = true; CreateUserWizard.Visible = false; Label_ErrorMessage.Visible = false; Label_Title.Visible = false; Label_Code.Visible = false; TextBox1.Visible = false; } else if (codeError == UserCodeError.CodeExpired) { Label_ErrorMessage.Text = "The given code has expired."; Label_ErrorMessage.Visible = true; } else if (codeError == UserCodeError.CodeUsed) { Label_ErrorMessage.Text = "The given code has already been used."; Label_ErrorMessage.Visible = true; } else if (codeError == UserCodeError.CodeDoesntExist) { Label_ErrorMessage.Text = "The given code does not exist."; Label_ErrorMessage.Visible = true; } } else { Label_ErrorMessage.Text = "Username already exists."; Label_ErrorMessage.Visible = true; } } else { Label_ErrorMessage.Text = "Email is invalid."; Label_ErrorMessage.Visible = true; } } }