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

|M| 防止按钮二次提交时,验证控件对这个按钮就无效了 怎么办 谢谢
<script   type= "text/javascript ">                                        
            var       option= "Once ";  
            function   Twice()      
            {      
                    if(option== "Once ")      
                    {      
                            //document.all( "btnOk ").Enable       =       false;    
                            return   false;      
                    }      
                    option       =       "Once ";                                                            
            }
           
</script>
<asp:Button   ID= "btnOk "   Text= "保存 "   runat= "server "   OnClick= "btnOk_Click "     OnClientClick= "   return   Twice() "> </asp:Button>

点击保存的时候就直接跑过验证了
问题应该在OnClientClick= "   return   Twice() "   这里


------解决方案--------------------
不要写在button的click中

写在form的 onsubmit 中
<form name= "test " runat= "server " onsubmit= "return Twice(); ">
------解决方案--------------------
有个替代的方式,就是用VS自带的验证控件。
------解决方案--------------------
用Custom验证控件,这样只需要将你上面的JS函数名赋给验证控件就可以了 !
------解决方案--------------------
不能使用asp.net服务器 button 改成input button runat=server

<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "testButtonEnable.aspx.cs " Inherits= "testButtonEnable " %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
<script type= "text/javascript ">
var option= "Once ";
function Twice()
{
alert(option);
if(option== "Once ")
{
document.all( "Button1 ").disabled = true;
option = "Twice ";
return true;
}
//option = "Once ";
return false;
}

</script>