Groups | Blog | Home
all groups > asp.net caching > september 2003 >

asp.net caching : TextBox won't update - Is this a Cache problem?


Charles Brauer
9/20/2003 12:35:24 PM
Hello,

I'm new to the newsgroups so sorry if this is a known issue :)

I am trying to use a TextBox like a Statusbar in a Web Application.
In other words, I want the TextBox to immediately update (refresh) its
contexts when the application runs.

In my test case I have a TextBox and a button. When I click the button,
(MyButtonClick shown below) I update the text. When I run the code,
I only see the last string ("Step 10" ) in the browser window.

I would like to see all the intermediate updates (Step 1, Step 2, ... etc.).
As you can see by my code below, I have tried various statements to force
the page to update each time the TextBox text has changed, but nothing
works, all I see is the last text: "Step 10".

Any suggestions would be greatly appreciated.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Threading;
namespace Test {
public class WebForm : System.Web.UI.Page {
protected System.Web.UI.WebControls.TextBox MyTextBox;
protected System.Web.UI.WebControls.Button MyButton;
private void Page_Load(object sender, System.EventArgs e) {
Response.Expires = -1000;
Response.Cache.SetExpires(DateTime.Now);
Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache);
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e) {
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent() {
this.MyButton.Click += new System.EventHandler(this.MyButton_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion

private void MyButton_Click(object sender, System.EventArgs e) {
for (int k=0; k<=10; k++) {
MyTextBox.Text = "Step " + k;
Response.Flush();
Response.Cache.SetExpires(DateTime.Now);
Thread.Sleep(500);
}
}
}

jiany NO[at]SPAM online.microsoft.com
9/22/2003 7:55:07 AM
Hi Charles,

Based on my research and experience, we should do it in the client script.
Please refer to the following code snippet:

--------------Test.aspx-------------
<html>
<head>
<Script Language = "VBScript">
<!--
Dim I
I = 0
Function DoClick()
document.myForm.TextBox1.value = "Step"&I
I = I+1
If I <= 10 Then
SETTIMEOUT "DoClick",1000
End If
End Function

-->
</Script>
</head>
<body>
<form id="myForm" runat="server">
<asp:TextBox id="TextBox1" style="Z-INDEX: 102; LEFT: 192px; POSITION:
absolute; TOP: 32px" runat="server"
Width="112px" Height="32px"></asp:TextBox>
<br>
<input type="button" value="ClickMe" onclick="DoClick()">
<br>
</form>
</body>
</html>
----------------------------------------------------------

Does it answer your question? If I have misunderstood your concern, plesae
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
<MCSD>
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Alvin Bruney
9/23/2003 10:27:33 PM
the system doesn't work this way. once this code is called it executes in
interity until it is done. when it is done it sends a page to the user with
the final value (10). you trying to create a splash screen of sorts. it is
not a trivial process.

[quoted text, click to view]

AddThis Social Bookmark Button