首次单击后禁用按钮 [英] Disable button after first click

查看:61
本文介绍了首次单击后禁用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道首先使用.aspx--点击
后点击按钮的方法/代码,以防止人们在等待时多次点击

服务器响应。


我尝试通过为按钮添加java脚本来完成此操作。但是,没用..


请帮忙!谢谢

Anyone knows the method/codes to disable the clicked button after first
click by using .aspx-- to prevent people to click many time when waiting for
the server response.

I tried to do this by adding a java script for the button. But, useless..

Please help! Thank you

推荐答案

使用Javascript(客户端

你可以在.cs文件中添加一个javascript onclick处理程序作为unde


string x =" document.Form1.Button1.disabled = true"

this.Button1.Attributes.Add(" onclick",x)


在服务器端执行相同操作


将以下内容添加到按钮单击事件处理程序中{即函数--private void Button1_Click (对象发送者,System.EventArgs e)

this.Button1.Enabled = false
Using Javascript(Client side
You can add a javascript onclick handler in the .cs file as unde

string x = "document.Form1.Button1.disabled=true"
this.Button1.Attributes.Add("onclick",x)

To do the same on the server side

add the following to your button click event handler { i.e the function --private void Button1_Click(object sender, System.EventArgs e)
this.Button1.Enabled=false


Sinity,


我正准备在我的网站上发布代码来执行此操作,但是你去了:


它会停止提交,但更好的是它会调用一些相同的.Net客户端

边码,如果任何必填字段验证器

无效且页面实际上没有提交,则不会禁用该按钮。


< script language =" java脚本">

<! -

var submitcount = 0;


function disableSubmit()

{

if(typeof(Page_ClientValidate)==''function'')

{

if(Page_ClientValidate()= = true)

{

返回checkSubmit();

}

其他

{

返回true;

}

}

其他

{

返回checkSubmit();

}

}


函数checkSubmit()

{

if(submitcount == 0)

{

submitcount ++;返回true;

}

其他

{

alert(''此表格已提交。' );返回false;

}

}

// - >

< / script>


将它连接到你的按钮,如下所示:

SubmitButton.Attributes.Add(" onClick"," javascript :返回

disableSubmit();")

此致,


-

S. Justin Gengo,MCP

Web开发人员


免费代码库位于:
www.aboutfortunate.com


混乱无序。

Nietzche

" Sinity" < SI **** @ msn.com>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP11.phx.gbl ...
Sinity,

I''m just about to post the code to do this on my website, but here you go:

It stops the submit, but even better it calls some of the same .Net client
side code and doesn''t disable the button if any required field validators
aren''t valid and the page doesn''t actually submit.

<script language="javascript">
<!--
var submitcount=0;

function disableSubmit()
{
if (typeof(Page_ClientValidate)==''function'')
{
if (Page_ClientValidate() == true)
{
return checkSubmit();
}
else
{
return true;
}
}
else
{
return checkSubmit();
}
}

function checkSubmit()
{
if (submitcount == 0)
{
submitcount++; return true;
}
else
{
alert(''This form has already been submitted.''); return false;
}
}
//-->
</script>

Attach it to your button like so:

SubmitButton.Attributes.Add("onClick", "javascript: return
disableSubmit();")
Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Sinity" <si****@msn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
任何人都知道使用.aspx--首先单击按钮后禁用单击按钮的方法/代码,以防止人们在等待服务器响应
时多次点击。

我试过通过为按钮添加java脚本来完成此操作。但是,没用..

请帮忙!谢谢
Anyone knows the method/codes to disable the clicked button after first
click by using .aspx-- to prevent people to click many time when waiting for the server response.

I tried to do this by adding a java script for the button. But, useless..

Please help! Thank you



> if(Page_ClientValidate()== true)
> if (Page_ClientValidate() == true)
{
return checkSubmit();
}

{
返回true; <<< -----你的意思是回归虚假;对吗?
}


Homa Wong

" S. Justin Gengo < SJ ***** @ aboutfortunate.com>在消息新闻中写道:< ud ************** @ TK2MSFTNGP10.phx.gbl> ... Sinity,

我即将张贴在我的网站上执行此操作的代码,但是在这里你去了:

它会停止提交,但更好的是它会调用一些相同的.Net客户端
端代码并且不会如果任何必填字段验证器无效且页面实际上没有提交,则禁用该按钮。

< script language =" javascript">
<! -
var submitcount = 0;

函数disableSubmit()
{
if(typeof(Page_ClientValidate)==''function'')
{
if(Page_ClientValidate()== true)
{
返回checkSubmit();
}


返回true;
}
}

{
返回checkSubmit();
}
}

function checkSubmit()
{
if(submitcount == 0)
{
submitcount ++;返回true;
}

{
警告(''此表已提交。'');返回false;
}
//
< / script>

将它连接到您的按钮,如下所示:

SubmitButton.Attributes.Add(" onClick"," javascript :return
disableSubmit();")

此致,

-
S. Justin Gengo,MCP
Web开发人员

免费代码库:
www.aboutfortunate.com

出于混乱,订单。
Nietzche

" Sinity" < SI **** @ msn.com>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP11.phx.gbl ...
{
return checkSubmit();
}
else
{
return true; <<< ----- You mean return false; right?
}
Homa Wong
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message news:<ud**************@TK2MSFTNGP10.phx.gbl>... Sinity,

I''m just about to post the code to do this on my website, but here you go:

It stops the submit, but even better it calls some of the same .Net client
side code and doesn''t disable the button if any required field validators
aren''t valid and the page doesn''t actually submit.

<script language="javascript">
<!--
var submitcount=0;

function disableSubmit()
{
if (typeof(Page_ClientValidate)==''function'')
{
if (Page_ClientValidate() == true)
{
return checkSubmit();
}
else
{
return true;
}
}
else
{
return checkSubmit();
}
}

function checkSubmit()
{
if (submitcount == 0)
{
submitcount++; return true;
}
else
{
alert(''This form has already been submitted.''); return false;
}
}
//-->
</script>

Attach it to your button like so:

SubmitButton.Attributes.Add("onClick", "javascript: return
disableSubmit();")
Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Sinity" <si****@msn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
任何人都知道方法/代码首先使用.aspx--单击后禁用单击的按钮,以防止人们在等待
Anyone knows the method/codes to disable the clicked button after first
click by using .aspx-- to prevent people to click many time when waiting


服务器响应时多次点击。

我尝试通过为按钮添加java脚本来完成此操作。但是,没用..

请帮忙!谢谢
the server response.

I tried to do this by adding a java script for the button. But, useless..

Please help! Thank you



这篇关于首次单击后禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆