需求:在dropdownlist ddlIsAlone_SelectedIndexChanged 事件触发以前弹出一个 confirm确认框,
如果点击OK的话,执行后台 ,
如果点击 cancel 不执行后台。
c#后台注册代码如下 。
ddl.Attributes.Add("onchange ", "if(check(" + i + ")){__doPostBack( ' " +ddl.ClientID+" ', '');}else{return(false);} ");其中 check()是一个javascript方法,主要判断选择的值。
现在问题是 弹出了confirm 的对话框,但是 
如果选择了OK 提示如下错误 
Microsoft JScript runtime error: '__doPostBack' is undefined

解决方案 »

  1.   

    本帖最后由 net_lover 于 2012-02-21 15:31:18 编辑
      

  2.   

    ddl.Attributes.Add("onchange","return confirm('Are You True Submit?');");
      

  3.   

    直接写
    return confirm是不行的,return 之后是无法提交的
      

  4.   

     <asp:DropDownList ID="DropDownList3" runat="server"  onselectedindexchanged="DropDownList3_SelectedIndexChanged">
                <asp:ListItem>choose</asp:ListItem>
            <asp:ListItem>delete</asp:ListItem>
            <asp:ListItem>save</asp:ListItem>
        </asp:DropDownList> if (!Page.IsPostBack)
            {
                DropDownList3.Attributes.Add("onchange", "if(confirm(\'确认删除吗?\')){__doPostBack( ' " + DropDownList3.ClientID + " ', ' ');}else{return(false);} ");
            }
     protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
        {
            Random ran = new Random();
            Label1.Text = "执行了后台事件" + ran.Next().ToString();
        }