2016-09-13 48 views
-2

如何在運行過程或函數時更改asp net visual basic中的文本標籤。 例如,當項目驗證某些東西時,標籤說的是一樣的。 (對不起,我不會說英語)更改文本標籤asp net

+2

你能提供一些你想要達到的樣本代碼嗎?目前你的問題不清楚。 –

+0

我沒有代碼,例如在安裝過程中更改文本,而運行程序(提取文件...)我需要在asp網絡 –

回答

3

我認爲你正在嘗試做的: - 有一種狀態標籤的不斷變化取決於當前任務 文本 - 在執行過程/函數應用程序線程(通過點擊按鈕爲例)

該如何處理呢?: 的方式我真的這樣做如下: 要求: - 一個定時器連接到您的形式 - 一個按鈕和一個標籤(只是我的例子)

下面是代碼我的做法怎麼會是:

private String currentStatus = "Idle"; 
    /* 
    * Use this while working with Lists or other kinds of arrays 
    * private object syncObject = new object(); 
    */ 
    private void button1_Click(object sender, EventArgs e) 
    { 
     // Keep in mind that you should disable the button while the thread is running 
     new Thread(new ThreadStart(DoTask)).Start(); 
    } 

    private void DoTask() 
    { 
     /* 
     * If you are working with Lists for example 
     * you should use a lock to prevent modifications 
     * while actually iterating the list. 
     * Thats how you use it: 
     * lock(syncObject){// You can do it for a single or a bunch of list actions 
     *  list.Add(item); 
     * } 
     */ 
     currentStatus = "Waiting..."; 
     Thread.Sleep(1000); 
     currentStatus = "Scanning..."; 
     Thread.Sleep(1000); 
     currentStatus = "Extracting data..."; 
     Thread.Sleep(1000); 
     currentStatus = "Done!"; 
    } 

    private void tickTimer_Tick(object sender, EventArgs e) 
    { 
     statusLabel.Text = currentStatus; 
    } 

請記住: 你不能改變任何控制值一樣標籤文字或其他主題!這就是爲什麼我使用這個字符串字段。

我希望它有幫助:)