protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserId"] != null)
        {
            string UserId = Request.QueryString["UserId"].ToString();
            name.Text = UserId;
        }
        else
        {
            string js = @"<script type='text/javascript'>window.onload=function(){alert('你还没有登录!');}</script>";
            Response.Write(js);
            //Response.Redirect("../Login.aspx");
        }
    }为啥 我这个不能弹出这个警告对话框呢  如果我要在它没有登录时弹出对话框 然后跳转到登录页应该怎样实现呢  我这种实现可以不 

解决方案 »

  1.   


    ClientScript.RegisterStartupScript(GetType(),"","<script>alert('你还没登陆哦亲!');window.location.href='Login.aspx'</script>");
      

  2.   

    你不就是判断如果没登录就跳转到登录页面么?
    这个你放在load事件中,如果session为空可以跳转,是先弹出对话框,点击确定后,再跳转到登录页
      

  3.   

            if (Session["UserId"] != null)
            {
               // string UserId = Request.QueryString["UserId"].ToString();
               // name.Text = UserId;
            }
            else
            {
                string js = @"<script type='text/javascript'>alert('你还没有登录!');window.location='Login.aspx';</script>";
                Response.Write(js);
                //Response.Redirect("../Login.aspx");
            }
      

  4.   

    可以采用 Ajax实现 ScriptManager.RegisterClientScriptBlock(UpdatePanel1,this.GetType(),null,"alert('请先登录..')",true);
      

  5.   

    我感觉 最好的 是 MessageBox.Show();
      

  6.   


    protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserId"] != null)
            {
                string UserId = Request.QueryString["UserId"].ToString();
                name.Text = UserId;
            }
            else
            {
                string js = @"<script type='text/javascript'>alert('你还没有登录!');</script>";
                Response.Write(js);
                //Response.Redirect("../Login.aspx");
            }
        }不用写onload,因为response.write写在html代码的最前面的.
      

  7.   

    response.write("<script>alert('登录超时,请重新登录。');window.location.href='url'</script>");
      

  8.   

    那如果禁用了javascript不就直接进入后台啦
      

  9.   

    如何实现 
    把Redirect放在下面根本就不会弹出窗口 就直接跳转啦
    不要用location 因为可能一禁用javascript就直接进入后台咯
      

  10.   

    那如何实现判断为空弹出窗口 直接跳转安 
    如果我用location 禁用javascript 不就直接进入我后台啦 
    求 实现
      

  11.   

    我是用MessageBox.Show();做的 不过在 Win 7系统 IIS 7.5 上面出了问题 不弹出来了,现在还未解决
      

  12.   

    如果禁用啦 javascript 如何实现 
      

  13.   

    Response.Write("<script>alert('要请先登入哦!');window.location.href='load.aspx';</script>");
      

  14.   

    晕咯 这样 如果 我禁用了javascript 不就 直接访问该页面了
      

  15.   

    为什么要加@呢   还有你加个断点调试下就知道了吗  最好吧ONLAOD去掉咯  我觉得