<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm5.aspx.cs" Inherits="web.WebForm5" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager" runat="server" />
    <asp:UpdatePanel ID="upList" runat="server">
        <ContentTemplate>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
            <asp:Timer ID="tmUpdate" runat="server" Enabled="false" OnTick="tmUpdate_Tick" Interval="2000" />
        </ContentTemplate>
    </asp:UpdatePanel>
    <div>
    </div>
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace web
{
    public partial class WebForm5 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {        }        protected void tmUpdate_Tick(object sender, EventArgs e)
        {
            if (Session[Session.SessionID] != null)
            {
                TextBox1.Text = Session[Session.SessionID].ToString();
                if (TextBox1.Text == "100")
                {
                    Session.Remove(Session.SessionID);
                    tmUpdate.Enabled = false;
                }
            }        }        protected void Button1_Click(object sender, EventArgs e)
        {
            System.Threading.Thread NewTh = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(Update));
            //System.Threading.Thread NewTh = new System.Threading.Thread(new System.Threading.ThreadStart(Update)); 
            NewTh.SetApartmentState(System.Threading.ApartmentState.STA);
            NewTh.Start(Session);
            tmUpdate.Enabled = true;
            //while (NewTh.ThreadState == System.Threading.ThreadState.Running) 
            //{ 
            //} 
        }        void Update(Object _Session)
        {
            //System.Web.HttpContext.Current.Session["1"] = DateTime.Now; 
            System.Threading.Thread.Sleep(3000);
            System.Web.SessionState.HttpSessionState session = (System.Web.SessionState.HttpSessionState)_Session;
            System.Threading.Thread.Sleep(3000);
            session[session.SessionID] = "10";
            System.Threading.Thread.Sleep(3000);
            Session[session.SessionID] = "30";
            System.Threading.Thread.Sleep(3000);
            Session[session.SessionID] = "50";
            System.Threading.Thread.Sleep(3000);
            Session[session.SessionID] = "80";
            System.Threading.Thread.Sleep(3000);
            Session[session.SessionID] = "100";
            System.Threading.Thread.Sleep(3000); 
        }
    
    }
}上面是我的页面,我要实现的功能就是
当点击了button的时候,开一个线程去执行一段代码,那段代码的进度保存在一个Session当中
页面中的Timer每两秒去读一下现在的进度,并显示出来但怪的是,读到的只有"10",而"30,50,80,100"都读不到,
我有点理解不了谢谢

解决方案 »

  1.   


    上面有sp1234大哥的回复 
    http://topic.csdn.net/u/20090320/11/a943fc60-5d65-417c-9483-0ad0d8c50ced.html
      

  2.   

    你把Session.SessionId换成一个固定值
      

  3.   

    ---------------------------
    我的并不是去更改页面控件的内容
    我是去更改session的内容谢谢
      

  4.   


            protected void Button1_Click(object sender, EventArgs e)
            {
                Session[Session.SessionID] = "0";
                System.Threading.Thread NewTh = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(Update));
                //System.Threading.Thread NewTh = new System.Threading.Thread(new System.Threading.ThreadStart(Update)); 
                NewTh.SetApartmentState(System.Threading.ApartmentState.STA);
                NewTh.Start(Session);
                tmUpdate.Enabled = true;
                //while (NewTh.ThreadState == System.Threading.ThreadState.Running) 
                //{ 
                //} 
            }
      

  5.   

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Reflection;
    using System.Xml;
    using System.Data.SqlClient;
     
    using System.Messaging;
    using System.Text.RegularExpressions;
    using System.Net;
    using System.Data.OleDb;
    namespace Csdn
    {
        [AjaxPro.AjaxNamespace("AJ")]
        public partial class Default : System.Web.UI.Page
        {
            System.Web.SessionState.HttpSessionState _Session;
            protected void Page_Load(object sender, EventArgs e)
            {
                Response.Expires = -100;
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                AjaxPro.Utility.RegisterTypeForAjax(typeof(Default), this);          
            }      
            [AjaxPro.AjaxMethod]
            public String GetSessionValue()
            {
                if (Session["a"] != null) return Session["a"].ToString();
                else return "-----";
            }
            protected void Button1_Click(object sender, EventArgs e)
            {             
                    System.Threading.Thread NewTh = new System.Threading.Thread(new System.Threading.ThreadStart(this.Update));
                   
                    NewTh.Start();
                    ClientScript.RegisterStartupScript(this.GetType(), "a", "window.setInterval(showvalue, 1000);", true);            
            }        void Update()
            {            try
                {                Session["a"] = "10";
                    System.Threading.Thread.Sleep(3000);
                    Session["a"] = "30";
                    System.Threading.Thread.Sleep(3000);
                    Session["a"] = "50";
                    System.Threading.Thread.Sleep(3000);
                    Session["a"] = "80";
                    System.Threading.Thread.Sleep(3000);
                    Session["a"] = "100";
                    System.Threading.Thread.Sleep(3000);
                  
                }
                catch
                { }
            }      
         
        }
    }
     
      

  6.   

    前台:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Csdn.Default"
     
     %><%@ Register Assembly="ZFControls" Namespace="ZFControls" TagPrefix="cc1" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html style="height:100%" xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
        <style>
            *
            {
                font:menu;
            }
            
            
            
            .CalendarArrow
            {
                CURSOR: pointer;font-weight:bold;
            }
        </style>
      
      
     
         <script type="text/javascript">
     
        
         
         function showvalue()
         {
           
            div1.innerHTML= AJ.GetSessionValue().value
         }

         </script>
      
    </head><body  >
     
      <form id="form1" runat="server">
        
        
     <asp:Button ID="btnNext" runat="server" Text="确定" OnClick="Button1_Click"  />
     
         
         <div id="div1"></div>
     </form>
    </body>
    </html>