⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javascriptupdater.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
字号:
namespace PowerEasy.Controls
{
    using System;
    using System.Collections.ObjectModel;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    [NonVisualControl, PersistChildren(false), ParseChildren(true)]
    public class JavaScriptUpdater : Control
    {
        private Collection<PowerEasy.Controls.UpdatePanel> _UpdatePanels = new Collection<PowerEasy.Controls.UpdatePanel>();
        private const string BasicScripts = "if (!window.UpdatePanels) window.UpdatePanels = {};\r\nUpdatePanels._createUpdateMethod = function(btnId)\r\n{\r\n\treturn function()\r\n\t{\r\n\t\t__doPostBack(btnId, '');\r\n    }\r\n}";
        private string clientButtonId;
        private bool initialized;
        private bool m_Enabled = true;
        private string m_MethodName;
        private const string RegisterMethodTemplate = "\nUpdatePanels['{0}'] = UpdatePanels._createUpdateMethod('{1}');";

        public event EventHandler<ResolveUpdatePanelEventArgs> ResolveUpdatePanel;

        private System.Web.UI.UpdatePanel FindUpdatePanel(string id)
        {
            System.Web.UI.UpdatePanel updatePanel = null;
            if (id != null)
            {
                updatePanel = this.NamingContainer.FindControl(id) as System.Web.UI.UpdatePanel;
            }
            if (updatePanel == null)
            {
                ResolveUpdatePanelEventArgs e = new ResolveUpdatePanelEventArgs(id);
                this.OnResolveUpdatePanel(e);
                updatePanel = e.UpdatePanel;
            }
            return updatePanel;
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Page.InitComplete += new EventHandler(this.Page_InitComplete);
        }

        private void OnResolveUpdatePanel(ResolveUpdatePanelEventArgs e)
        {
            if (this.ResolveUpdatePanel != null)
            {
                this.ResolveUpdatePanel(this, e);
            }
        }

        private void OnTrigger(object sender, EventArgs e)
        {
            if (this.Enabled)
            {
                foreach (PowerEasy.Controls.UpdatePanel panel in this.UpdatePanels)
                {
                    System.Web.UI.UpdatePanel panel2 = this.FindUpdatePanel(panel.UpdatePanelId);
                    if (panel2 != null)
                    {
                        panel2.Update();
                    }
                }
            }
        }

        private void Page_InitComplete(object sender, EventArgs e)
        {
            this.initialized = true;
            if (this.Enabled)
            {
                this.Page.Load += new EventHandler(this.Page_Load);
                this.Page.PreRenderComplete += new EventHandler(this.Page_PreRenderComplete);
            }
        }

        private void Page_Load(object sender, EventArgs e)
        {
            LinkButton child = new LinkButton();
            child.Text = "Update";
            child.ID = this.ID + "Button";
            child.Style[HtmlTextWriterStyle.Display] = "none";
            child.Click += new EventHandler(this.OnTrigger);
            this.Page.Form.Controls.Add(child);
            this.clientButtonId = child.UniqueID;
            ScriptManager.GetCurrent(this.Page).RegisterAsyncPostBackControl(child);
        }

        private void Page_PreRenderComplete(object sender, EventArgs e)
        {
            this.Page.ClientScript.RegisterClientScriptBlock(base.GetType(), "BasicScripts", "if (!window.UpdatePanels) window.UpdatePanels = {};\r\nUpdatePanels._createUpdateMethod = function(btnId)\r\n{\r\n\treturn function()\r\n\t{\r\n\t\t__doPostBack(btnId, '');\r\n    }\r\n}", true);
            this.Page.ClientScript.RegisterClientScriptBlock(base.GetType(), this.clientButtonId, string.Format("\nUpdatePanels['{0}'] = UpdatePanels._createUpdateMethod('{1}');", this.MethodName, this.clientButtonId), true);
        }

        public bool Enabled
        {
            get
            {
                return this.m_Enabled;
            }
            set
            {
                if (this.initialized)
                {
                    throw new InvalidOperationException("Cannot set the property after initialized.");
                }
                this.m_Enabled = value;
            }
        }

        public string MethodName
        {
            get
            {
                return this.m_MethodName;
            }
            set
            {
                if (this.initialized)
                {
                    throw new InvalidOperationException("Cannot set the property after initialized.");
                }
                this.m_MethodName = value;
            }
        }

        [PersistenceMode(PersistenceMode.InnerProperty)]
        public Collection<PowerEasy.Controls.UpdatePanel> UpdatePanels
        {
            get
            {
                return this._UpdatePanels;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -