/// <summary> /// OnPreRender override - Bind data. /// </summary> /// <param name="e">Event args</param> protected override void OnPreRender(EventArgs e) { bool dataBinded = false; if (UseUpdatePanel) { int favoriteId = ValidationHelper.GetInteger(hdnValue.Value, 0); if (favoriteId > 0) { ForumUserFavoritesInfoProvider.DeleteForumUserFavoritesInfo(favoriteId); ClearCache(); BindData(); dataBinded = true; if (UpdatePanel != null) { UpdatePanel.Update(); } } } if (!dataBinded) { BindData(); } hdnValue.Value = null; base.OnPreRender(e); }
/// <summary> /// Handles delete button action - deletes user favorite. /// </summary> protected void btnDelete_OnCommand(object sender, CommandEventArgs e) { if (e.CommandName == "delete") { int favoriteId = ValidationHelper.GetInteger(e.CommandArgument, 0); ForumUserFavoritesInfoProvider.DeleteForumUserFavoritesInfo(favoriteId); ClearCache(); BindData(); } }
/// <summary> /// Bind data to repeater. /// </summary> private void BindData() { if (MembershipContext.AuthenticatedUser != null) { int userId = MembershipContext.AuthenticatedUser.UserID; int siteId = SiteContext.CurrentSiteID; // If sitename was specified if (SiteName != String.Empty) { // Get site ID SiteInfo si = SiteInfoProvider.GetSiteInfo(SiteName); if (si != null) { siteId = si.SiteID; } } // Get user favorites DataSet ds = null; // Try to get data from cache using (var cs = new CachedSection <DataSet>(ref ds, CacheMinutes, true, CacheItemName, "forumfavorites", userId, siteId)) { if (cs.LoadData) { // Get the data ds = ForumUserFavoritesInfoProvider.GetFavorites(userId, siteId); // Save to the cache if (cs.Cached) { // Save to the cache cs.CacheDependency = GetCacheDependency(); } cs.Data = ds; } } // Bind data, even empty dataset - delete of last item rptFavorites.DataSource = ds; rptFavorites.DataBind(); // Hide control if no data if (DataHelper.DataSourceIsEmpty(ds)) { if (HideControlForZeroRows) { Visible = false; } else { plcEmptyDSTagEnd.Visible = true; plcEmptyDSTagBegin.Visible = true; } } else { plcEmptyDSTagEnd.Visible = false; plcEmptyDSTagBegin.Visible = false; } } }