当前位置:编程学习 > C#/ASP.NET >>

网页中设置等待

我在C#中
点击一个按钮让lable的值改变

但是我想让他1秒钟之后改变!

不知道如何设置等待时间 --------------------编程问答-------------------- 线程等待..
Timer控件.. --------------------编程问答-------------------- 我想得到确切的代码或者例子 --------------------编程问答-------------------- System.Threading.Thread.Sleep(1000); --------------------编程问答-------------------- //按钮事件
private void btnSleep_Click(object sender, System.EventArgs e)
{
   ThreadStart thr_start_func = new ThreadStart(CreateThread);
   Thread fThread = new Thread (thr_start_func);
   fThread.Name = "MyThread";
   fThread.Start ();
}
//线程委托的函数
public void CreateThread()
{
   Thread.Sleep(1000);
   YourLable.Text = "New";
} --------------------编程问答-------------------- 我的意思是…………
页面有个lable和button

我点button后
在click事件里让lable的值为a

然后等一秒,lable的值成b了

楼上的方法却是等待了
但是看不到让lable成为a了! --------------------编程问答-------------------- 你在线程没有启动时候改变lable值为a,
线程等待一秒后再改为b就行了啊。 --------------------编程问答-------------------- //按钮事件
private void btnSleep_Click(object sender, System.EventArgs e)
{
   ThreadStart thr_start_func = new ThreadStart(CreateThread);
   Thread fThread = new Thread (thr_start_func);
   fThread.Name = "MyThread";
   fThread.Start ();
}
//线程委托的函数
public void CreateThread()
{
   Thread.Sleep(1000);
   YourLable.Text = "New";
}

我试了
能 改成a
但是改不成后面的值
你亲自测试了? --------------------编程问答-------------------- 这是我的代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.Label1.Text = "dddddddd";
        ThreadStart thr_start_func = new ThreadStart(CreateThread);
        Thread fThread = new Thread(thr_start_func);
        fThread.Name = "MyThread";
        fThread.Start();
    }
    //线程委托的函数
    public void CreateThread()
    {
        Thread.Sleep(1000);
        this.Label1.Text = "New";
    }

}
--------------------编程问答-------------------- 线程的确不能改变,用js吧。
<script LANGUAGE="JAVASCRIPT">
  var OldContent = '这里是旧内容';
  var NewContent = '这里是新内容';
function setContent()
{
  document.getElementById('YourLable').innerText = '这里是旧内容';       
  setTimeout("showNewContent()",2000);
}
function showNewContent() 
{
   document.getElementById('YourLable').innerText = '这里是新内容';
}
</script>
<asp:Label id=YourLable runat="server"></asp:Label>
<input type=button onclick="setContent()" value="改变内容" > --------------------编程问答-------------------- ajax.net timer控件试试 --------------------编程问答-------------------- 如果是线程,是新开了一个线程做这个事,所以你页面所在的主线程仍然是按照原来的时间走的,用js或者是timer控件可以实现 --------------------编程问答-------------------- 哦
知道了
谢谢各位

原来真的线程不行
以前也试过很多次

现在知道却是不行就好了

js的部分就不需要了
呵呵
只是为了达到某个效果
还是谢谢各位达人的帮助
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,