日期:2014-05-18  浏览次数:20396 次

confirm 条件判断后弹出确认对话框问题
我想在程序中通过一个判断后弹出确认对话框,可是跟踪程序发现,弹出程序可以通过运行,可在实际中却弹不出窗口,程序照样往下执行。我的按钮是放在UpdatePanel中的,程序执行到alert时会弹出窗口,可以执行到confirm那句时没有反映,就继续向下了,待全部执行完毕后才会弹出确认对框,请问如何更改才能使程序执行到confirm时就弱出确认对话框来选择?

C# code

    protected void ImageButton1_Click1(object sender, ImageClickEventArgs e)
    {
        if (lab_sy.Text == "0")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "msg1", "alert('房间已满!');", true);
            return;
        }
        
        if (edt_OldRoom.Text!="")
        {
           
             ScriptManager.RegisterStartupScript(this, this.GetType(), "msg1", "confirm('此人已经分配过,是否继续?');", true);

。。。。。。。
。。。。。。。。
           
        }
}




------解决方案--------------------
ScriptManager.RegisterStartupScript(GetType(), "", "<script>alert('房间已满!');</script>");

------解决方案--------------------
Web好像是不可能,除非用ajax。
------解决方案--------------------
用Response.Write("<script>confirm('此人已经分配过,是否继续?')</script>");能否?
------解决方案--------------------
这种确认的是属于客户端行为吧,你为ImageButton1添加click方法就会在点击时弹出确认对话框,都已经触发其后台click事件了,肯定不会先弹出确认对话框了,这个跟确认是否删除是一样道理的,
------解决方案--------------------
我提个思路,你别写在CS里,你先写在页面中 利用JS OnClientClick="return checkStatus()" 


------解决方案--------------------
看看对你有帮助没有:
using System;
using System.Web;
namespace ShowMessage
{
/// <summary>
/// Msg 的摘要说明。
/// </summary>
public class ShowMessage
{
public ShowMessage()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static void ShowMessage(string strMsg)
{
System.Web.HttpContext.Current.Response.Write("<Script Language='JavaScript'>window.alert('"+strMsg+"');</script>");
}
public static void ShowMessage(System.Web.UI.Page page, string strMsg)
{
page.Response.Write("<Script Language='JavaScript'>window.alert('"+strMsg+"');</script>");
}
public static void ShowMessage( string strMsg, string Url)
{
System.Web.HttpContext.Current.Response.Write("<Script Language='JavaScript'>window.alert('"+strMsg+"');window.location.href ='"+Url+"'</script>");
}
public static void ShowMessage( System.Web.UI.Page page,string strMsg, string Url)
{
page.Response.Write("<Script Language='JavaScript'>window.alert('"+strMsg+"');window.location.href ='"+Url+"'</script>");
}
public static void ShowConfirm(string strMsg, string strUrl_Yes, string strUrl_No)
{
System.Web.HttpContext.Current.Response.Write("<Script Language='JavaScript'>if ( window.confirm('"+strMsg+"')) { window.location.href='" + strUrl_Yes +
"' } else {window.location.href='"+ strUrl_No +"' };</script>");
}
}
}


------解决方案--------------------
还有一种就是在页面加载前先对要进行操作的数据进行处理,在满足什么条件下向控件中注册什么脚本
例如:按钮的text属性为:删除,我就在页面加载时进行如下处理if (this.Button1.Text == "删除")