2016-09-13 104 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; 
    } 

请记住: 你不能改变任何控制值一样标签文字或其他主题!这就是为什么我使用这个字符串字段。

我希望它有帮助:)