| /// <summary> /// This web part uses an SPGridView inside of an updatepanel to display a dataset. The update panel automatically handles /// all the ajaxy stuff for post backs with paging and sorting. /// </summary> [XmlRoot(Namespace = "SpaarneZiekenhuis.OCS.WebParts")] [Guid("41B3B790-7578-4cec-9F31-F342FD2B1192")] public class OcsQueue : System.Web.UI.WebControls.WebParts.WebPart { Timer timer = new Timer(); Label label1 = new Label(); private Label displayQueue; private TextBox inputName; [DefaultValue(""), WebBrowsable(true), Category("ProgressTemplate"), Personalizable(PersonalizationScope.Shared)] public string ImagePath { get; set; } [DefaultValue(""), WebBrowsable(true), Category("ProgressTemplate"), Personalizable(PersonalizationScope.Shared)] public string DisplayText { get; set; } protected override void CreateChildControls() { try { base.CreateChildControls(); //Fix for the UpdatePanel postback behaviour. EnsurePanelFix(); timer = new Timer(); UpdatePanel refreshName = new UpdatePanel(); displayQueue = new Label(); //Set up control properties. this.displayQueue.ID = "displayQueue"; this.displayQueue.Text = "Waiting in Queue"; refreshName.ID = "refreshName"; refreshName.UpdateMode = UpdatePanelUpdateMode.Conditional; refreshName.ChildrenAsTriggers = true; this.timer.ID = "TimerOcs"; this.timer.Interval = 10000; this.timer.Tick += new EventHandler<EventArgs>(ClickHandler); //Add the EventHandler to the Button. //Add the user interface (UI) controls to the UpdatePanel. refreshName.ContentTemplateContainer.Controls.Add(this.timer); refreshName.ContentTemplateContainer.Controls.Add(this.displayQueue); //The ScriptManager control must be added first. if (ScriptManager.GetCurrent(this.Page) == null) { ScriptManager scriptHandler = new ScriptManager(); scriptHandler.ID = "scriptHandler"; scriptHandler.EnablePartialRendering = true; this.Controls.Add(scriptHandler); } this.Controls.Add(refreshName); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } private void EnsurePanelFix() { if (this.Page.Form != null) { String fixupScript = @" _spBodyOnLoadFunctionNames.push(""_initFormActionAjax""); function _initFormActionAjax() { if (_spEscapedFormAction == document.forms[0].action) { document.forms[0]._initialAction = document.forms[0].action; } } var RestoreToOriginalFormActionCore = RestoreToOriginalFormAction; RestoreToOriginalFormAction = function() { if (_spOriginalFormAction != null) { RestoreToOriginalFormActionCore(); document.forms[0]._initialAction = document.forms[0].action; } }"; ScriptManager.RegisterStartupScript(this, typeof(OcsQueue), "UpdatePanelFixup", fixupScript, true); } } private void ClickHandler(object sender, EventArgs args) { this.displayQueue.Text = string.Format("Waiting in Queue {0}", GetWaitingQueue()); } |