class VisitorRecordControl : BaseFieldControl { public void UpdateItemFieldValue() { try { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(SPContext.Current.Site.ID)) { using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID)) { web.AllowUnsafeUpdates = true; SPList list = web.Lists[this.ListId]; SPListItem item = list.GetItemById(this.ItemId); if (item == null) return; if (ItemFieldValue != null) item[this.FieldName] = (Convert.ToInt32(this.ItemFieldValue.ToString()) + 1).ToString(); else item[this.FieldName] = "1"; item.SystemUpdate(); web.AllowUnsafeUpdates = false; } } }); }catch{} } protected override void Render(System.Web.UI.HtmlTextWriter output) { if (this.ControlMode == SPControlMode.Display) { this.UpdateItemFieldValue(); if (this.ItemFieldValue != null) { output.Write(this.ItemFieldValue.ToString()); } else { output.Write("0"); } } } } |