62,046
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Plan_L5.cs" Inherits="Line5_Plan" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>信息</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="100" OnTick="Timer1_Tick" Enabled="False"></asp:Timer>
<div id="div_ybxx" runat="server" style="width:100%; height:100%; top: 0px; left:0px; position: fixed; background-image: url('../images/ybxx.jpg');">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<table id="tb_ybxx" style="width:100%; font-family: 微软雅黑; font-size: 34px; color: #feecdd;" border="0">
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div id="div_jbgx" runat="server" style="width:100%; height:100%; top: 0px; left:0px; position: fixed; background-image: url('../images/jbgx.jpg');">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<table id="tb_jbgx" style="width:100%; font-family: 微软雅黑; font-size: 34px; color: #feecdd;" border="0">
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
//后台代码
public partial class Line5_Plan : System.Web.UI.Page
{
public static int flag = 0;
public static int flagYB = 0;
public static int SelCount = 0;
public static int jdbfb = 0;
public static int jdwith = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Timer1.Interval = 100;
Timer1.Enabled = true;
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Timer1.Enabled = false;
flag++;
switch (flag)
{
case 1:
this.div_ybxx.Style["Display"] = "Block"; //显示
this.div_jbgx.Style["Display"] = "None"; //隐藏
flagYB++;
switch (flagYB)
{
case 1:
ReadYBInfo_1(0, 9, 1);
flag = 0;
break;
case 2:
ReadYBInfo_1(9, 18, 2);
flag = 0;
break;
case 3:
ReadYBInfo_1(18, 27, 3);
flagYB = 0;
break;
}
break;
case 2:
this.div_ybxx.Style["Display"] = "None"; //隐藏
this.div_jbgx.Style["Display"] = "Block"; //显示
flag = 0;
break;
default:
flag = 0;
flagYB = 0;
break;
}
Timer1.Interval = 10000;
Timer1.Enabled = true;
}
private void ReadYBInfo_1(int SNo,int ENo,int flag)
{
//
}
}
protected async System.Threading.Tasks.Task<string> ReadYBInfo_1(string divid)
{
return await System.Threading.Tasks.Task<string>.Run(() =>
{
//你应该在这里连接数据库,读取表中的字段然后返回成一个组合,比如List啊比如你自己定义的每个控件的值的 键值对啊。
//我在这里把从数据库中采集的数据写在这里,然后直接返回到具体的timer方法中,由timer去做修改table的操作。
//现在只能显示this.div_ybxx.InnerHtml = (await ReadYBInfo_1()) + flag.ToString(); flag数值增加能看到这是当然的,你看看timer方咯
System.Threading.Thread.Sleep(500);
return divid;
});
}
protected async void Timer1_Tick(object sender, EventArgs e)
{
Timer1.Enabled = false;//不解释了这是关闭自己防止多次执行
flag++;//flag这个你之前就有很多我保留了
this.div_ybxx.Style["Display"]= this.div_ybxx.Style["Display"]=="None"?"Block":"None";//这是隐藏显示切换代码
this.div_jbgx.Style["Display"]=this.div_ybxx.Style["Display"]=="None"?"Block":"None";//这个跟上面一样,这里的写法是如果隐藏就显示否则就隐藏
if (this.div_ybxx.Style["Display"] == "None")//这里是具体修改div内元素的代码你当然不能按照这个直接修改div的InnerHtml了,你的lable修改应该放在这里啊。
{
this.div_ybxx.InnerHtml = (await ReadYBInfo_1(div_ybxx.ID))+flag.ToString();
}
else
{
this.div_jbgx.InnerHtml = (await ReadYBInfo_1(div_jbgx.ID))+flag.ToString();
}//修改代码结束,这里的if else就是看修改哪个div
Timer1.Interval = 1000;//重新执行timer不解释了
Timer1.Enabled = true;
}
protected async System.Threading.Tasks.Task<string> ReadYBInfo_1(string divid)
{
//这里连接数据库,读取表中的字段值赋值给前台的label控件
//我在这里把从数据库中采集的数据写在这里,然后把取到的数值赋值给table里面的td内的label控件,但是label并没有显示出来,
//现在只能显示this.div_ybxx.InnerHtml = (await ReadYBInfo_1()) + flag.ToString(); flag数值增加能看到
return await System.Threading.Tasks.Task<string>.Run(() =>
{
System.Threading.Thread.Sleep(500);
return divid;
});
}
// 前台的table表格
<tr style="height:130px">
<td style="width:2%"></td>
<td style="text-align: center">牌号</td>
<td style="text-align: center"><asp:Label ID="lb_ph1" runat="server" Text=""></asp:Label></td>
<td style="text-align: center"><asp:Label ID="lb_ph2" runat="server" Text=""></asp:Label></td>
</tr>
//前台的“牌号”不显示,lb_ph1和lb_ph2也不显示,只有一个空白的背景图片在切换
[/quote]
protected async System.Threading.Tasks.Task<string> ReadYBInfo_1(string divid)
{
return await System.Threading.Tasks.Task<string>.Run(() =>
{
//这是异步方法的核心,你需要把耗时操作都写在这里面,甚至说严格点你需要把整个方法都写在这里面
System.Threading.Thread.Sleep(500);//这里模拟的是具体的耗时操作,你在实际代码中需要用实际耗时操作替换这一句
return divid;//这里的返回值要和Task<string> 的尖括号中一致,不仅是这个Task 包括这个方法也要一致。
});
}
protected async System.Threading.Tasks.Task<string> ReadYBInfo_1(string divid)
{
//这里连接数据库,读取表中的字段值赋值给前台的label控件
//我在这里把从数据库中采集的数据写在这里,然后把取到的数值赋值给table里面的td内的label控件,但是label并没有显示出来,
//现在只能显示this.div_ybxx.InnerHtml = (await ReadYBInfo_1()) + flag.ToString(); flag数值增加能看到
return await System.Threading.Tasks.Task<string>.Run(() =>
{
System.Threading.Thread.Sleep(500);
return divid;
});
}
// 前台的table表格
<tr style="height:130px">
<td style="width:2%"></td>
<td style="text-align: center">牌号</td>
<td style="text-align: center"><asp:Label ID="lb_ph1" runat="server" Text=""></asp:Label></td>
<td style="text-align: center"><asp:Label ID="lb_ph2" runat="server" Text=""></asp:Label></td>
</tr>
//前台的“牌号”不显示,lb_ph1和lb_ph2也不显示,只有一个空白的背景图片在切换
<%@ Page Language="C#" Async="true" %>
<!--这是aspx的页面头你应该看的出来吧-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
<!--这部分就是你以前写的aspx.cs我只不过都写在一个页面了方便你复制粘贴-->
public static int flag = 0;
protected async void Timer1_Tick(object sender, EventArgs e)
{
Timer1.Enabled = false;
flag++;
this.div_ybxx.Style["Display"]= this.div_ybxx.Style["Display"]=="None"?"Block":"None";
this.div_jbgx.Style["Display"]=this.div_ybxx.Style["Display"]=="None"?"Block":"None";
if (this.div_ybxx.Style["Display"] == "None")
{
this.div_ybxx.InnerHtml = (await ReadYBInfo_1(div_ybxx.ID))+flag.ToString();
}
else
{
this.div_jbgx.InnerHtml = (await ReadYBInfo_1(div_jbgx.ID))+flag.ToString();
}
Timer1.Interval = 1000;
Timer1.Enabled = true;
}
protected async System.Threading.Tasks.Task<string> ReadYBInfo_1(string divid)
{
return await System.Threading.Tasks.Task<string>.Run(() =>
{
System.Threading.Thread.Sleep(500);
return divid;
});
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Timer1.Interval = 100;
Timer1.Enabled = true;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<!--这里才是以前的aspx页面代码部分,你当然要新建aspx粘贴进去了,html不报错iis已经很给你面子了-->
<head id="Head1" runat="server">
<title>UpdatePanelUpdateMode Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1"
runat="server" />
<asp:UpdatePanel ID="updatepanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="100" OnTick="Timer1_Tick" Enabled="False"></asp:Timer>
<div id="div_ybxx" runat="server" style="width: 100%; height: 100%; top: 0px; left: 0px; position: fixed; background-image: url('../images/ybxx.jpg');">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<table id="tb_ybxx" style="width: 100%; font-family: 微软雅黑; font-size: 34px; color: #feecdd;" border="0">
a</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div id="div_jbgx" runat="server" style="width: 100%; height: 100%; top: 0px; left: 0px; position: fixed; background-image: url('../images/jbgx.jpg');">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<table id="tb_jbgx" style="width: 100%; font-family: 微软雅黑; font-size: 34px; color: #feecdd;" border="0">
b</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" Async="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public static int flag = 0;
protected async void Timer1_Tick(object sender, EventArgs e)
{
Timer1.Enabled = false;
flag++;
this.div_ybxx.Style["Display"]= this.div_ybxx.Style["Display"]=="None"?"Block":"None";
this.div_jbgx.Style["Display"]=this.div_ybxx.Style["Display"]=="None"?"Block":"None";
if (this.div_ybxx.Style["Display"] == "None")
{
this.div_ybxx.InnerHtml = (await ReadYBInfo_1(div_ybxx.ID))+flag.ToString();
}
else
{
this.div_jbgx.InnerHtml = (await ReadYBInfo_1(div_jbgx.ID))+flag.ToString();
}
Timer1.Interval = 1000;
Timer1.Enabled = true;
}
protected async System.Threading.Tasks.Task<string> ReadYBInfo_1(string divid)
{
return await System.Threading.Tasks.Task<string>.Run(() =>
{
System.Threading.Thread.Sleep(500);
return divid;
});
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Timer1.Interval = 100;
Timer1.Enabled = true;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>UpdatePanelUpdateMode Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1"
runat="server" />
<asp:UpdatePanel ID="updatepanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="100" OnTick="Timer1_Tick" Enabled="False"></asp:Timer>
<div id="div_ybxx" runat="server" style="width: 100%; height: 100%; top: 0px; left: 0px; position: fixed; background-image: url('../images/ybxx.jpg');">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<table id="tb_ybxx" style="width: 100%; font-family: 微软雅黑; font-size: 34px; color: #feecdd;" border="0">
a</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div id="div_jbgx" runat="server" style="width: 100%; height: 100%; top: 0px; left: 0px; position: fixed; background-image: url('../images/jbgx.jpg');">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<table id="tb_jbgx" style="width: 100%; font-family: 微软雅黑; font-size: 34px; color: #feecdd;" border="0">
b</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
ScriptManager1.RegisterAsyncPostBackControl(Timer1);
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
Timer1.Interval = 100;
Timer1.Enabled = true;
}
protected void Timer1_Tick(object sender, EventArgs e)
{
this.div_ybxx.Style["Display"]= this.div_ybxx.Style["Display"]=="None"?"Block":"None";
this.div_jbgx.Style["Display"]=this.div_ybxx.Style["Display"]=="None"?"Block":"None";
}
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager1.RegisterAsyncPostBackControl(Timer1);
if (!IsPostBack)
{
Timer1.Interval = 100;
Timer1.Enabled = true;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>UpdatePanelUpdateMode Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1"
runat="server" />
<asp:UpdatePanel ID="updatepanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="100" OnTick="Timer1_Tick" Enabled="False"></asp:Timer>
<div id="div_ybxx" runat="server" style="width: 100%; height: 100%; top: 0px; left: 0px; position: fixed; background-image: url('../images/ybxx.jpg');">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<table id="tb_ybxx" style="width: 100%; font-family: 微软雅黑; font-size: 34px; color: #feecdd;" border="0">
a</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div id="div_jbgx" runat="server" style="width: 100%; height: 100%; top: 0px; left: 0px; position: fixed; background-image: url('../images/jbgx.jpg');">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<table id="tb_jbgx" style="width: 100%; font-family: 微软雅黑; font-size: 34px; color: #feecdd;" border="0">
b</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected DateTime LastUpdate
{
get
{
return (DateTime)(ViewState["LastUpdate"] ?? DateTime.Now);
}
set
{
ViewState["LastUpdate"] = value;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Timer1.Interval = 100;
Timer1.Enabled = true;
}
protected void Timer1_Tick(object sender, EventArgs e)
{
this.div_ybxx.Style["Display"] = this.div_ybxx.Style["Display"]== "None"?"Block":"None";
this.div_jbgx.Style["Display"] = this.div_ybxx.Style["Display"]== "None"?"Block":"None";
}
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager1.RegisterAsyncPostBackControl(Button1);
if (!IsPostBack)
{
LastUpdate = DateTime.Now;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>UpdatePanelUpdateMode Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1"
runat="server" />
<asp:UpdatePanel ID="updatepanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="100" OnTick="Timer1_Tick" Enabled="False"></asp:Timer>
<div id="div_ybxx" runat="server" style="width: 100%; height: 100%; top: 0px; left: 0px; position: fixed; background-image: url('../images/ybxx.jpg');">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<table id="tb_ybxx" style="width: 100%; font-family: 微软雅黑; font-size: 34px; color: #feecdd;" border="0">
a</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div id="div_jbgx" runat="server" style="width: 100%; height: 100%; top: 0px; left: 0px; position: fixed; background-image: url('../images/jbgx.jpg');">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<table id="tb_jbgx" style="width: 100%; font-family: 微软雅黑; font-size: 34px; color: #feecdd;" border="0">
b</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="Button1" Text="Button1" runat="server" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>