參考來源:http://www.iooooo.com/websites/siland/blogview.asp?logID=1031&2035533686=906533351
VB.NET寫法:
<script language="javascript">
<!--
function disableOtherSubmit()
{ var obj = event.srcElement;
var objs = document.getElementsByTagName('INPUT');
for(var i=0; i<objs.length; i++)
{
if(objs[i].type.toLowerCase() == 'submit')
{
objs[i].disabled = true;
}
} }
/ /-->
</script>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load
'在這裡放置使用者程式碼以初始化網頁
If Not IsPostBack Then
...
Dim sb As New System.Text.StringBuilder()
sb.Append("if (typeof(Page_ClientValidate) == 'function') { if (Page_ClientValidate() == false) { return false; }}") '保证验证函数的执行
sb.Append("if(window.confirm('確定要執行嗎??')==false) return false;") '自定义客户端脚本
sb.Append("disableOtherSubmit();") ' disable所有submit按钮
sb.Append(Me.ClientScript.GetPostBackEventReference(Me.Button1, "")) '用__doPostBack来提交,保证按钮的服务器端click事件执行
sb.Append(";")
Button1.Attributes.Add("onclick", sb.ToString())
end if
end sub
VB.NET寫法:
<script language="javascript">
<!--
function disableOtherSubmit()
{ var obj = event.srcElement;
var objs = document.getElementsByTagName('INPUT');
for(var i=0; i<objs.length; i++)
{
if(objs[i].type.toLowerCase() == 'submit')
{
objs[i].disabled = true;
}
} }
/ /-->
</script>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load
'在這裡放置使用者程式碼以初始化網頁
If Not IsPostBack Then
...
Dim sb As New System.Text.StringBuilder()
sb.Append("if (typeof(Page_ClientValidate) == 'function') { if (Page_ClientValidate() == false) { return false; }}") '保证验证函数的执行
sb.Append("if(window.confirm('確定要執行嗎??')==false) return false;") '自定义客户端脚本
sb.Append("disableOtherSubmit();") ' disable所有submit按钮
sb.Append(Me.ClientScript.GetPostBackEventReference(Me.Button1, "")) '用__doPostBack来提交,保证按钮的服务器端click事件执行
sb.Append(";")
Button1.Attributes.Add("onclick", sb.ToString())
end if
end sub