【发布时间】:2014-05-15 21:50:31
【问题描述】:
我有一个使用 VS2012 用 C# 编写的简单应用程序,位于 Web 表单应用程序中。
有一个按钮可以开始处理,我想通过在标签中放置一些文本来让用户更新处理进度。我想我可以将 Label 控件放在 UpdatePanel 中,然后在 Button 单击事件期间通过调用 UpdatePanel Update() 方法触发 Label 文本的更改。但是,标签文本的唯一更改是在单击事件完成并显示标签文本“处理完成”之后。
这是我的 xml:
这是后面的代码:
protected void btnCreateFiles_Click(object sender, EventArgs e)
{
//Do some stuff
//Show the message that the application is processing
lblCaption.Text = "Processing...updating label data";
ProgressUpdatePanel.ContentTemplateContainer.Controls.Add(lblCaption);
ProgressUpdatePanel.Update();
//Call to database to insert labels
//Call to database to get the labels
lblCaption.Text = "Processing...creating label files.";
ProgressUpdatePanel.ContentTemplateContainer.Controls.Add(lblCaption);
ProgressUpdatePanel.Update();
//Create Text files from data
lblCaption.Text = "Processing...updating label counts.";
ProgressUpdatePanel.ContentTemplateContainer.Controls.Add(lblCaption);
ProgressUpdatePanel.Update();
//Database call to insert count records
//Create file of count records
lblCaption.Text = "Processing...completed.";
ProgressUpdatePanel.ContentTemplateContainer.Controls.Add(lblCaption);
ProgressUpdatePanel.Update();
}
唯一显示的文本是上次更新...“处理中...已完成。”
为什么其他更新不会触发更改标签文本?
谢谢
更新要求
我稍微改变了我的要求。而不是多次更新。我在进度模板中添加了一个标签,以在处理开始时显示初始消息,然后在处理完成时使用 lblCaption 标签显示另一条消息。但是,当第二次单击该按钮时,会显示两条消息:“正在创建文件……请稍候……”和“正在处理……已完成”。
如何重置进度模板中的文本以仅显示“请稍候...”消息而不显示“处理中...完成”消息?
这是现在的 aspx 文件:
现在按钮事件处理程序方法如下所示:
protected void btnCreateFiles_Click(object sender, EventArgs e)
{
//All of the processing is done here...
//This works correctly the first time a user click the button
//But the second time, this text remains and the 'Please wait...' text from the lblProgress label
// is added above this text.
ProgressUpdatePanel.ContentTemplateContainer.Controls.Add(lblCaption);
ProgressUpdatePanel.Update();
lblCaption.Text = "Processing...completed.";
}
更新
我尝试了以下方法来清除标签 lblCaption 中的文本。我已通过代码执行此代码,因为标签文本未清除。
我尝试在 Page_Load() 方法中重置标签,如下所示:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtBoxEnvironment.Text = CurrentEnvironment;
DAL.setConnectionString(CurrentEnvironment);
}
ProgressUpdatePanel.ContentTemplateContainer.Controls.Add(lblCaption);
ProgressUpdatePanel.Update();
lblCaption.Text = "";
}
我已删除 ProgressUpatePanel 方法并尝试仅设置标签文本但未重置。
我错过了什么?
【问题讨论】:
-
请出示相关客户代码。
-
我拥有的唯一客户端代码是上面显示的 xml。我没有任何 javascript 等。
标签: c# asp.net updatepanel