我有一個簡單的應用程序,使用VS2012在C#中編寫,在Web窗體應用程序中。使用ASP.Net在點擊事件期間多次更新標籤文本
有一個按鈕開始處理,我想通過在Label中放置一些文本來給用戶更新處理進度。我想我可以將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.";
}
UPDATE 我嘗試了以下操作來清除標籤中的文本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等。 –