实现前台页面中提示中读秒操作需要用JavaScript在操作:
<script type="text/javascript"> var second = 5; var timer; function change() { second--; if (second > -1) { document.getElementById("second").innerHTML = second; timer = setTimeout('change()', 1000); } else { clearTimeout(timer); } } timer = setTimeout('change()', 1000); </script>
对于的页面代码:
<div id="message_body"> <br /> <br /> <asp:Label ID="Label1" runat="server" Text="[显示消息信息]"></asp:Label>,将在 <strong><span id=second>5</span></strong> 秒后自动跳转到指定页面。
<br /> <asp:Button ID="Button1" runat="server" Text="点击按钮手动跳转" Width="228px" onclick="Button1_Click" /> </div>
在页面需要提示的地方加上这句话:
//提示信息后继续操作 Session["GotoURL"] = "~/Admin/Movie_Edit.aspx"; //提示后跳转到的页面 Session["Info"] = "添加电影数据成功";//提示的信息内容 Response.Redirect("~/User/Message.aspx");//转到信息提示页面
后台代码获取该页面前用户操作的页面信息,可以在这个提示页面显示后自动跳转到之前或指定的页面.
using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Threading;// using System.Timers;// namespace Movies.UserControl.User { public partial class Control_User_Message : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { //显示信息 string info = Session["Info"].ToString(); Label1.Text = info; //自动跳转到页面 string goUrl = Session["GotoURL"].ToString(); HtmlMetaView(this.Page, goUrl.Substring(1)); } /// <summary> /// 跳转到指定页面 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button1_Click(object sender, EventArgs e) { string goUrl = Session["GotoURL"].ToString(); Response.Redirect(goUrl); } /// <summary> /// 定时跳转(方法) /// </summary> /// <param name="page">当前页面</param> /// <param name="_url">跳转到的页面</param> public static void HtmlMetaView(System.Web.UI.Page page, string _url) { System.Web.UI.HtmlControls.HtmlMeta reflash = new System.Web.UI.HtmlControls.HtmlMeta(); reflash.HttpEquiv = "Refresh"; reflash.Content = "5;url=" + _url; page.Header.Controls.Add(reflash); } }