using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using WebControls.HLAdminService; namespace WebControls { public partial class OKBNamedDetailControl : System.Web.UI.UserControl { // delegate for the stored event public delegate void OKBItemStoredDelegate(Object sender, EventArgs e); //event for the store button public event OKBItemStoredDelegate OKBItemStored; //private namedOKBItem private static NamedOKBItem namedOKBItem; /* * Page_load is always executed when the control will be refreshed */ protected void Page_Load(object sender, EventArgs e) { if (UCWidth == null) { UCWidth = "100%"; } if (UCHeight == null) { UCHeight = "150"; } this.Panel1.Width = new Unit(UCWidth); this.Panel1.Height = new Unit(UCHeight); if (IsPostBack) { namedOKBItem = (NamedOKBItem)ViewState["namedOKBItem"]; } this.setEnableState(); } /* * setNamedOKBItem, set a new OKBItem to the Control * the Item is stored in the viewstate of the control */ public void setNamedOKBItem(NamedOKBItem okbItem) { namedOKBItem = okbItem; if (namedOKBItem != null) { tbName.Text = namedOKBItem.Name; tbDescription.Text = namedOKBItem.Description; tbName.DataBind(); tbDescription.DataBind(); } ViewState["namedOKBItem"] = namedOKBItem; this.setEnableState(); } /* * getNamedOKBItem, to get the current stored OKBItem */ public NamedOKBItem getNamedOKBItem() { return namedOKBItem; } /* * setEnableState, is to se the enabledstate of the store button */ private void setEnableState() { if (namedOKBItem == null) { this.Visible = false; } else { this.Visible = true; } } private bool isModified() { if (namedOKBItem.Name == tbName.Text && namedOKBItem.Description == tbDescription.Text) { return false; } else { return true; } } /* * DataBind is to bind data manually */ public override void DataBind() { base.DataBind(); tbName.DataBind(); tbDescription.DataBind(); } /* * btnStore_Click, is always executed, if the store button is clicked */ protected void btnStore_Click(object sender, EventArgs e) { if (namedOKBItem != null) { namedOKBItem.Name = tbName.Text; namedOKBItem.Description = tbDescription.Text; ViewState["namedOKBItem"] = namedOKBItem; base.DataBind(); this.setEnableState(); if (null != OKBItemStored) { OKBItemStored(this, EventArgs.Empty); } } } private string UCWidth; private string UCHeight; public string Width { get { return UCWidth; } set { UCWidth = value; } } public string Height { get { return UCHeight; } set { UCHeight = value; } } /* * tbName_TextChanged, is to refresh the view State of the control */ protected void tbName_TextChanged(object sender, EventArgs e) { setEnableState(); } /* * tbDescription_TextChanged, is to refresh the view State of the control */ protected void tbDescription_TextChanged(object sender, EventArgs e) { setEnableState(); } } }