User641655154 posted
I'm trying to develop a progress bar that shows the status of server side process..
Im facing a problem that my session variable is not updating....
this is my code
private void LongTask()
{
for (int i = 0; i < 11; i++)
{
System.Threading.Thread.Sleep(1000);
Session["State"] = i + 1;
}
Session["State"] = 100;
}
public void Button1_Click(object sender, System.EventArgs e)
{
Thread thread = new Thread(new ThreadStart(LongTask));
thread.Start();
Session["State"] = 1;// initialize session variable
OpenProgressBar(this.Page);
}
public static void OpenProgressBar(System.Web.UI.Page Page)
{
StringBuilder sbScript = new StringBuilder();
sbScript.Append("<script language='JavaScript' type='text/javascript'>\n");
sbScript.Append("<!--\n");
sbScript.Append("window.showModalDialog('Progress.aspx','','dialogHeight: 150px; dialogWidth: 350px; edge: Raised; center: Yes; help: No; resizable: No; status: No;scroll:No;');\n");
sbScript.Append("// -->\n");
sbScript.Append("</script>\n");
Page.RegisterClientScriptBlock("OpenProgressBar", sbScript.ToString());
}
and inside Progress.aspx ..
private int state = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["State"] != null)
{
state = Convert.ToInt32(Session["State"].ToString());
}
else
{
Session["State"] = 0;
}
if (state > 0 && state <= 10)
{
this.lblMessages.Text = "Processing...";
this.panelProgress.Width = state * 30;
this.lblPercent.Text = state * 10 + "%";
//Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "", "<script>window.setTimeout('window.theForm.submit()',100);</script>");
Page.RegisterStartupScript("", "<script>window.setTimeout('window.form1.submit()',100);</script>");
}
if (state == 100)
{
this.panelProgress.Visible = false;
this.panelBarSide.Visible = false;
this.lblMessages.Text = "Task Completed!";
Page.RegisterStartupScript("", "<script>window.close();</script>");
}
}
here session variable is intilizingg but not updatingg as in the LongTask function
so im gettting session value as "1 " in each page load of progress.aspx