程序思路是想在循环中触发条件时让用户选择是否继续运行或终止运行,代码如下:
private void Button1_Click(object sender, System.EventArgs e)
{
int i;
for(i=0;i<10;i++)
{
if(i==1)
{
if(!Page.IsStartupScriptRegistered("isok"))
Page.RegisterStartupScript("isok","<script>if(confirm('您确认?')) document.all.tmp.value='true'; else document.all.tmp.value='false';</script>");
                            if(tmp.Value !="false")
break;
else
         //执行处理

}
if(i==5)
{
if(!Page.IsStartupScriptRegistered("isok"))
Page.RegisterStartupScript("isok","<script>if(confirm('您确认?')) document.all.tmp.value='true';</script>");
if(tmp.Value !="false")
break;
else
//执行处理 } }
                   }
但发现运行程序时,服务器端并没有等待客户的答复就直接运行下面的代码了,请问各位大虾怎么解决。

解决方案 »

  1.   

    在PageLoad里加:
    Button1.Attributes.Add("onclick","return confirm('您确认?'))
      

  2.   

    Page.RegisterStartupScript("isok","<script>if(confirm('您确认?')) document.all.tmp.value='true'; else document.all.tmp.value='false';</script>");
    放在page_lode里
      

  3.   

    this.Response.Write("<script language='javascript'>");
    this.Response.Write("aa=window.confirm('打印列纸宽度不够,是否返回列表设置页');");
    this.Response.Write("if(aa==true)");
    this.Response.Write("{");
    this.Response.Write("window.location.href='rows.aspx'");
    this.Response.Write(" } ");
    this.Response.Write("if(aa==false){");
    this.Response.Write("window.location.href='select.aspx'");
    this.Response.Write("}");
    this.Response.Write("</script>");
      

  4.   

    to  billfancy(bill)
    你这个想法是不可能实现的,搜索一下CSDN,可以看到很多这样的想法了.
    为什么?
    因为HTTP本身就是无状态的页面,它不可能象CS程序一样时刻与数据库连接,而只能在页面加载时与服务器连接,加载完成,它就是客户端了.
    如果可以如你所想,那在弹出对话框时,是认为加载完成了呢还是未加载完成?
    所以,你只能在客户端弹出脚本,不能在服务端运行时取条件判断.
    如果非要如此,也是有办法的.
    在用户点击操作时,碰到需要条件的情况下,你可把当前用户操作的内容隐藏起来,然后在页面上显示选择项(非脚本弹出),让用户再选择,之后,就可以根据选择情况继续进行操作了.
      

  5.   

    Here is a way:
    private void Button1_Click(object sender, System.EventArgs e)
    {
    //Using js: show confirm . If true, Button2.click(),else Button3.click().

    private void Button2_Click(object sender, System.EventArgs e)
    {
    //.......do something 

    private void Button3_Click(object sender, System.EventArgs e)
    {
    //.......do something

    Do this to let the buttons unvisiabled:(Don't use "Visiable=false"!)
    Button2.Width=0;Button2.Height=0;Button3.Width=0;Button3.Height=0;