我有一段代码是放在一个BUTTON事件里写的,这个button是具有runat=server功能的,但是我现在不想回传服务器,然后我就发现了button里有个属性叫OnclientClick,请问我这段代码应该怎么修改才能写在onclientclick中正确? if (c == "")
            {
                Response.Write("<script language = javascript>alert(\"请选择一个客户!\")</script>");
            }
            if (c != "")
            {                Response.Write("<script type='text/javascript'>window.open('/subsystem/DDM/projectname.aspx?clientID=" + Convert.ToInt32(clientId_lb.Text) + "','win1','height=500,width=500,left=400,edge=1,center=1,resizable=1,status=0,scrollbars=yes');</script>");
                //Response.Write("<script type='text/javascript'>window.showModalDialog('/subsystem/DDM/projectname.aspx?clientID=" + DropDownList2.SelectedValue + "','win1','height=500,width=500,left=400,edge=1,center=1,resizable=1,status=0,scrollbars=yes');</script>");//
            }

解决方案 »

  1.   

    只能写到程序外部。
    这样OnclientClick访问不到js
      

  2.   


    if (c== "")
        {
            alert("请选择一个客户!");
        }
        else if (c!= "")
        {
             window.open("Default3.aspx?clientID=" + string + ",'win1','height=500,width=500,left=400,edge=1,center=1,resizable=1,status=0,scrollbars=yes'"); 
        }
    string 是在前端抓到clientId_lb.Text的值
      

  3.   


    if (c== "")
        {
            alert("请选择一个客户!");
        }
        else if (c!= "")
        {
             window.open("Default3.aspx?clientID=" + string + ",'win1','height=500,width=500,left=400,edge=1,center=1,resizable=1,status=0,scrollbars=yes'"); 
        }
    string 是在前端抓到clientId_lb.Text的值
      

  4.   

    将这段代码写在一个方法里,然后设置button的属性OnclientClick="方法名称"