后台页面一直打开在那里不动。如果有人在前台页面注册用户,后台页面就自动弹出一个提示,说有新人注册。想做到这样的效果,代码怎么写?谢谢。

解决方案 »

  1.   

    注册的时候多加条数据记录到另外的表(不是用户注册表,站内信息表)后台用ajax去提取有没有新的站内消息。有的话,做些什么事……
      

  2.   

     public static void AlertAndRedirect(string message, string toURL)
            {
                #region
                string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
                HttpContext.Current.Response.Write(string.Format(js, message, toURL));
                #endregion
            }
      

  3.   

    用iframe隐藏框架不停刷新 配合javascirpt代码弹出窗体可以完成相应效果
      

  4.   

    要用线程,和ajax实现监控数据库表的是否有新记录
      

  5.   

    我这儿有一个有点类似的例子,给你做下参考吧/// <summary>
    /// 是否异步请求
    /// </summary>
    private bool IsAynx
    {
       get
       {
           return Request["isaynx"] != null ? true : false;
       }
    }/// <summary>
    /// 查询条件
    /// </summary>
    private string Query
    {
       get
       {
           return Request["qry"] != null ? return Request.QueryString["qry"].ToString() : "";   
       }
    }……protected void Page_Load(object sender, EventArgs e)
    {
        if (IsAynx)
        {
            if (Query != "")
            {
                //在这里进行后端逻辑处理 访问数据库等
                //和传统CS代码写法相同
                  ……
                  getInfo(returnValue);
            }
        }
    }……/// <summary>
    /// 返回查询结果
    /// </summary>
    /// <param name="Msg">查询结果</param>
    private void getInfo(string Msg)
    {
        string returnValue = string.Format("<Message>{0}</Message>", Server.UrlEncode(Msg));    Response.ContentType = "text/xml";
        Response.AppendHeader("Cache-Control", "no-cache");
        Response.Write(returnValue);
        Response.Flush();
        Response.End();
    }
    前端代码这么处理<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>TestPage</title>
        <script language="javascript" type="text/javascript">
        var xmlHttp;
        var str = "aabbcc";
        
        function createXMLHttp()
        {
            if(window.ActiveXObject)
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else if(window.XMLHttpRequest)
            {
                xmlHttp = new XMLHttpRequest();
            }
        }
        
        function doSearch()
        {
            if(document.getElementById("txt") != null)
            {
                str = document.getElementById("txt").value;
                window.setInterval("Start()", 1000);        
            }
        }
        
        function Start()
        {
            if(str != "")
            {
                createXMLHttp();
                var url = "Default9.aspx?qry=" + escape(str) + "&isaynx=1&t=" + new Date().getTime();
                xmlHttp.open("GET", url, true);
                xmlHttp.onreadystatechange = handleCallBack;
                xmlHttp.send(null);    
            }
        }
        
        function handleCallBack()
        {
            if(xmlHttp.readyState == 4)
            {
                if(xmlHttp.status == 200)
                {
                    ShowMessage(xmlHttp.responseXML);    
                }
            }
        }
        
        function ShowMessage(Val)
        {
            if(Val.getElementsByTagName("Message")[0] != null)
            {
                var s = Val.getElementsByTagName("Message")[0].firstChild.data;
                alert(s);
            }
        }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <table width="100%" cellpadding="0" cellspacing="0">
                <tr>
                    <td style="width:100%" align="left">
                        <asp:TextBox ID="txt" runat="server" Width="100%"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td style="width:100%" align="left">
                        <input type="button" value="Begin" onclick="doSearch();" />&nbsp;&nbsp;
                    </td>
                </tr>
            </table>
        </form>
    </body>
    </html>
    当时自己做着玩儿的页面,也是1秒钟刷新一次,看看是不是有点价值吧