日期:2014-05-19  浏览次数:20401 次

ASP.NET对话框
各位好,小弟今天在写程序时碰到了一个问题,想请各位帮帮忙解决一下.
具体情况是这样的,我想在ASP.NET页面中弹出一个 "确定 "对话框,当我按下 "确定 "按钮时,页面转到另外一个页面,比如我想当我按下 "确定 "时转到 "index.aspx "这相页面,我现在的在ASP.NET的前台页面中写了一段javascript代码:
<script   language= "javascript ">
    if(document.all( "passTxt ").value!= " ")
    {
            alert(document.all( "passTxt ").value);
            document.all( "passTxt ").value= " ";
    }
   
</script>
passTxt是一个隐藏控件,在后台我也写了一段代码,
        passTxt.Value= "对不起!此用户已经存在了,请使用其它用户名!!! ";
        TextBox1.Text=logname1;
        Response.Redirect( "index.aspx ");

这是我所写的代码,但运行结果是:页面直接转到 "index.aspx "页面,根本不弹出对话框,但当我把Response.Redirect( "index.aspx ")注解掉的话,就会弹出对话框,到底怎样才能实现当我按下按钮 "确定 "时才转到 "index.aspx "页面呢?请各位帮帮忙了!先在此谢谢各位了.

------解决方案--------------------
需要看看Button是怎么写的。
------解决方案--------------------
不能在服务器端直接做跳转,你可以这样写
Response.Write( " <script> alert( '对不起!此用户已经存在了,请使用其它用户名!!! ') </script> ");
Response.Write( " <script> window.location.replace( 'index.aspx ') </script> ");
------解决方案--------------------
在Response.Redirect前面的提示代码是无效的.
juedaihuaihuai(绝代坏坏(beyond myself)) 正解!
------解决方案--------------------
哪就用个分页或者DIV做嘛
------解决方案--------------------
如果是隐藏的话.JS是无法铺捉得到解决的.
------解决方案--------------------
确认框不是用alert的,用confirm弹一个窗口,如果用户点确定就返回TRUE,否则返回FALSE
你只要对返回值做判断再决定是否跳转就行了
------解决方案--------------------
button的onclick事件= "javascript:if(confirm( '对不起!此用户已经存在了,请使用其它用户名!!! '))location= 'index.aspx ';else location= 'index.aspx ' "