private void PopulateControls() { if (forum == null) { return; } if (thread == null) { return; } if ((thread.TotalReplies + 1) == forum.PostsPerPage) { nextPageNumber = PageNumber + 1; } else { nextPageNumber = PageNumber; } string pageUrl; string viewAllUrl = string.Empty; if (ForumConfiguration.CombineUrlParams) { pageUrl = SiteRoot + "/Forums/Thread.aspx?pageid=" + PageId.ToInvariantString() + "&t=" + threadId.ToInvariantString() + "~{0}"; viewAllUrl = SiteRoot + "/Forums/Thread.aspx?pageid=" + PageId.ToInvariantString() + "&t=" + threadId.ToInvariantString() + "~-1"; } else { pageUrl = SiteRoot + "/Forums/Thread.aspx?pageid=" + PageId.ToInvariantString() + "&mid=" + moduleId.ToInvariantString() + "&ItemID=" + ItemId.ToInvariantString() + "&thread=" + threadId.ToInvariantString() + "&pagenumber={0}"; } pgrTop.PageURLFormat = pageUrl; pgrTop.ShowFirstLast = true; pgrTop.CurrentIndex = PageNumber; pgrTop.PageSize = forum.ThreadsPerPage; pgrTop.PageCount = thread.TotalPages; pgrTop.Visible = (pgrTop.PageCount > 1); pgrBottom.PageURLFormat = pageUrl; pgrBottom.ShowFirstLast = true; pgrBottom.CurrentIndex = PageNumber; pgrBottom.PageSize = forum.ThreadsPerPage; pgrBottom.PageCount = thread.TotalPages; pgrBottom.Visible = (pgrBottom.PageCount > 1); if (ForumConfiguration.ShowPagerViewAllLink) { pgrTop.ViewAllUrl = viewAllUrl; pgrBottom.ViewAllUrl = viewAllUrl; } lnkNewPost.Text = ForumResources.ForumThreadViewReplyLabel; lnkNewPost.NavigateUrl = SiteRoot + "/Forums/EditPost.aspx?" + "thread=" + threadId.ToString() + "&forumid=" + forum.ItemId.ToInvariantString() + "&mid=" + moduleId.ToInvariantString() + "&pageid=" + PageId.ToString() + "&pagenumber=" + nextPageNumber.ToInvariantString(); lnkNewPost.Visible = WebUser.IsInRoles(forum.RolesThatCanPost) && !forum.Closed; lnkNewPostBottom.Visible = lnkNewPost.Visible; lnkNewPostBottom.Text = ForumResources.ForumThreadViewReplyLabel; lnkNewPostBottom.NavigateUrl = lnkNewPost.NavigateUrl; lnkLogin.Visible = !lnkNewPost.Visible && !Request.IsAuthenticated; lnkLoginBottom.Visible = lnkLogin.Visible; if ((thread.IsLocked || forum.Closed || thread.IsClosed(config.CloseThreadsOlderThanDays)) && (!isEditable)) { lnkNewPost.Visible = false; lnkNewPostBottom.Visible = false; lblClosedTop.Visible = true; lblClosedBottom.Visible = true; } //lnkLogin.NavigateUrl = SiteRoot + "/Secure/Login.aspx?returnurl=" + Server.UrlEncode(Request.RawUrl); lnkLogin.Text = ForumResources.ForumsLoginRequiredLink; //lnkLoginBottom.NavigateUrl = SiteRoot + "/Secure/Login.aspx?returnurl=" + Server.UrlEncode(Request.RawUrl); lnkLoginBottom.Text = ForumResources.ForumsLoginRequiredLink; if (useReverseSort) { using (IDataReader reader = thread.GetPostsReverseSorted()) { this.rptMessages.DataSource = reader; this.rptMessages.DataBind(); } pgrTop.Visible = false; pgrBottom.Visible = false; lnkNewPost.Visible = false; lnkNewPostBottom.Visible = false; } else { if (PageNumber == -1) { using (IDataReader reader = thread.GetPosts()) { rptMessages.DataSource = reader; rptMessages.DataBind(); } if (thread.TotalPages <= 1) { pgrTop.Visible = false; pgrBottom.Visible = false; } } else { using (IDataReader reader = thread.GetPosts(PageNumber)) { rptMessages.DataSource = reader; rptMessages.DataBind(); } } if ( (rptMessages.Items.Count == 0) && (ItemId > -1) ) { // when the last post in a thread is deleted // the ForumPostEditPage redirects to this page // but it will hit this code and go back to the forum instead of showing // the empty thread string redirectUrl; if (ForumConfiguration.CombineUrlParams) { if (pageNumber > 1) { // try going back to page 1 redirectUrl = SiteRoot + "/Forums/Thread.aspx?pageid=" + PageId.ToInvariantString() + "&t=" + threadId.ToInvariantString() + "~1"; } else { redirectUrl = SiteRoot + "/Forums/ForumView.aspx?pageid=" + PageId.ToInvariantString() + "&f=" + ItemId.ToInvariantString() + "~1"; } } else { redirectUrl = SiteRoot + "/Forums/ForumView.aspx?" + "ItemID=" + ItemId.ToInvariantString() + "&pageid=" + PageId.ToInvariantString() + "&mid=" + moduleId.ToInvariantString(); } WebUtils.SetupRedirect(this, redirectUrl); } else { thread.UpdateThreadViewStats(); } } }