.net如何实现10秒倒计时
来源:互联网 发布:win10添加数据保护 编辑:程序博客网 时间:2024/05/17 17:58
我用的是vs2005
问题是 :现在有个查询手机号码的功能 点击查询的时候先把号码插入到一个表中 同时显示10秒倒计时 等到时间为0的时候就从另一个表中查询数据并显示出来 我之前用js写的只是时间到0的时候再插入数据同时查询数据 可是查询的结果为空 原因是后台的处理程序并没有那么快把插入的号码处理掉
页面代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>手机号码查询</title>
<style type="text/css">
body
{
font-size:small;
}
.bt
{
filter : alpha(opacity=0);
display:none;
}
</style>
<script language="javascript" type="text/javascript">
var t = 10;// 规定为10s
function sarTime() {
var phone = document.getElementById("<%=this.txtPhone.ClientID %>").value;
if (phone == "") {
alert("手机号码不能为空!");
return false;
}
else if (phone != "") {
var re = /^1[3|4|5|8][0-9]/d{4,8}$/;
if (!re.test(phone)) {
alert("请输入正确的手机号码!");
return false;
} else {
if (t > 0) {
document.getElementById("<%=this.lblMes.ClientID %>").innerHTML = "正在查询,请稍后...(" + t.toString() + ")";
t--;
if (t == 8) {//执行一次即可 到这步的时候时间就不动了
document.getElementById("<%=this.Button1.ClientID %>").click();
}
setTimeout("sarTime()", 1000);
} else {
document.getElementById("<%=this.btnSearch.ClientID %>").click();
t = 10; //重新赋值计算
}
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align:left;">
<asp:Label ID="Label2" runat="server" Text="音乐盒查询" Font-Bold="True"
Font-Size="Large"></asp:Label>
<br />
<br />
<div>
<asp:Label ID="Label1" runat="server" Text="请输入手机号码:"></asp:Label>
<asp:TextBox ID="txtPhone" runat="server" Width="192px"></asp:TextBox>
<input id="btnS" type="button" value="查询" onclick="sarTime()" />
<asp:Button ID="btnSearch" runat="server" Text="" onclick="btnSearch_Click" CssClass="bt" />
<asp:Button ID="Button1" runat="server" Text="" onclick="Button1_Click" CssClass="bt" />
<br />
<asp:Label ID="lblMes" runat="server" ForeColor="Red"></asp:Label>
<asp:GridView ID="gvPhone" runat="server" AutoGenerateColumns="False"
onrowdatabound="gvPhone_RowDataBound" Width="801px" AllowPaging="True">
<RowStyle HorizontalAlign="Center" />
<Columns>
<asp:BoundField DataField="createtime" HeaderText="查询时间" />
<asp:BoundField DataField="mobile" HeaderText="手机号码" />
<asp:BoundField DataField="tonecode" HeaderText="音乐盒编号" />
<asp:BoundField DataField="name" HeaderText="音乐盒名称" />
<asp:BoundField DataField="price" HeaderText="资费(分)" />
</Columns>
<HeaderStyle BackColor="#9999FF" />
</asp:GridView>
</div>
</form>
</body>
</html>
后台代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.lblMes.Text = "";//清空提示消息
}
}
protected void Button1_Click(object sender, EventArgs e)
{
//输入的号码
string phone = this.txtPhone.Text.Trim().ToString();
this.lblMes.Text = "";//清空提示消息
this.txtPhone.Enabled = false;//输入号码框不可用
//先插入到cring_MessageQueue表里
string strSql = string.Format("insert into cring_MessageQueue(message) values ('TYPE=command;AppID=SMS;OP=QueryBox;Mobile={0}')", phone);
DBHelper.ExecuteNonQuery(strSql); //如果插入数据成功,则执行里面操作
}
protected void btnSearch_Click(object sender, EventArgs e)
{
try
{
//输入的号码
string phone = this.txtPhone.Text.Trim().ToString();
this.lblMes.Text = "";//清空提示消息
//System.Threading.Thread.Sleep(10000);//让程序停止10秒
//从这张表里去数据并显示
string strSql2 = "select createtime,mobile,tonecode,name,price from cring_RecentSession_BoxInfo where mobile='" + phone + "'";
DataTable dt = DBHelper.GetDataTable(strSql2);//获取查询的集合
//绑定数据源
if (dt == null)
{
this.lblMes.Text = "没有您要查询的信息!";
this.txtPhone.Text = "";
this.txtPhone.Enabled = true;
}
this.txtPhone.Enabled = true;//输入号码框可用
this.txtPhone.Text = "";
this.gvPhone.DataSource = dt;
this.gvPhone.DataBind();
}
catch (Exception ex)
{
throw new Exception("查询出错!" + ex.ToString());
}
}
protected void gvPhone_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#999999'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=''");
}
}
}
- .net如何实现10秒倒计时
- 用 JS 实现10秒倒计时
- html 10秒 倒计时 (已实现)
- 15秒倒计时实现
- 时分秒倒计时 实现
- 10秒倒计时
- js倒计时10秒
- js 实现60秒倒计时
- jQuery实现5秒倒计时
- 按钮10秒可用倒计时
- JS实现倒计时(时、分,秒)
- js实现倒计时(天小时秒)
- JS实现的倒计时(时、分、秒)
- 通过获取的秒数实现倒计时
- android 代码片段,实现60秒倒计时
- JS实现倒计时(时、分,秒)
- 时分秒倒计时的js实现
- JS 倒计时实现代码(时、分,秒)
- 对字符的操作
- Linux的权限和所有权模型(粘滞位)
- 宏与内联函数(面试常考)--转自fisher_jiang的专栏-http://blog.csdn.net/fisher_jiang
- oracle专用服务器模式与共享服务器模式
- Subversion的安装和使用
- .net如何实现10秒倒计时
- 一个详细的VBA实例(连接SQL Server2000)
- perl 5.10新特性智能匹配操作符合~~介绍
- 慎用线程
- MetInfo2.0-3.0 吃掉 0day
- Jquery特效一:图片轮换显示
- Excel Application对象应用大全(一)
- Microsoft Enterprise Library 简介与请大家下载Microsoft Enterprise Library 5.0体验微软最新技术应用于企业信息平台
- Android更新下载进度条