Ext.Net 1.x_Ext.Net.TaskManager模拟进度条

一直很想做一个登陆时候的进度条 上图先:

Ext.Net 1.x_Ext.Net.TaskManager模拟进度条_第1张图片Ext.Net 1.x_Ext.Net.TaskManager模拟进度条_第2张图片

 

   <ext:Button ID="btnlogin" runat="Server" Text="登陆"  Icon="Accept" OnDirectClick="Login_Click" >
            </ext:Button>
             
    <ext:TaskManager ID="TaskManager1" runat="server">
        <Tasks>
            <ext:Task 
                TaskID="Task1"
                Interval="1000" 
                AutoRun="false">
                <DirectEvents>
                    <Update OnEvent="RefreshProgress" />
                </DirectEvents>                    
            </ext:Task>
        </Tasks>
    </ext:TaskManager>

 protected void Login_Click(object sender, DirectEventArgs e)
    {
        Model._Login _lg = new Model._Login();
        _lg.UserCode = this.txtusername.Text.Trim();
        _lg.Password = this.txtpassword.Text.Trim();
        BLL.Login lg = new BLL.Login();
        if (lg.UserLogin(_lg))
        {


            X.Msg.Show(new MessageBoxConfig
            {
                Title = "请等待",
                Message = "正在加载项",
                ProgressText = "初始化中...",
                Width = 300,
                Progress = true,
                Closable = false,
                AnimEl = this.btnlogin.ClientID
            });

            this.StartLongAction();
        }
        else 
        {
            X.Msg.Alert("警告", "账号或密码有误").Show();

        }

    }
    private void StartLongAction()
    {
        this.Session["Task1"] = 0;
        ThreadPool.QueueUserWorkItem(LongAction);

        this.TaskManager1.StartTask("Task1");
    }


    private void LongAction(object state)
    {
        for (int i = 0; i < 100; i++)
        {
            Thread.Sleep(100);
            this.Session["Task1"] = i + 1;
        }
        this.Session.Remove("Task1");
    }


    protected void RefreshProgress(object sender, DirectEventArgs e)
    {
        object progress = this.Session["Task1"];
        if (progress != null)
        {
            X.Msg.UpdateProgress(((int)progress) / 100f, string.Format(" {0} % {1}", progress.ToString(), 100));
        }
        else
        {
            this.TaskManager1.StopTask("Task1");
            X.MessageBox.Hide();
            //this.ResourceManager1.AddScript("Ext.Msg.notify('Done', 'Your items were loaded!');");
            Response.Redirect("Default.aspx");
        }
    }

你可能感兴趣的:(Ext.Net 1.x_Ext.Net.TaskManager模拟进度条)