如何禁用提交按钮? [英] How to disable a submit button?
本文介绍了如何禁用提交按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用以下代码我无法在点击后禁用提交btn。
< head runat = server >
< title > Untitled Page < / title >
< script 类型 = text / javascript >
函数DisableButton(){
document.getElementById(<% = Button4.ClientID %> )。disabled = true;
}
window.onbeforeunload = DisableButton;
< / script >
< asp:Button ID =Button4runat =serverToolTip =Please note down 您的 成员 ID for future reference
OnClick =Button4_Click
style =z-index:1; left: 185px; top: 2840px; position: absolute; height :30px;宽度:80px; font-size:large ForeColor =GreenText =提交/>
< script type = text / javascript language = JavaScript >
function DisableButton(){
document.getElementById(<% = Button4.ClientID %> )。disabled = true;
}
< / script >
此后添加[OnClientClick]属性来控制
< asp:Button ID =Button4runat =serverToolTip =请记下您的会员ID以备将来参考
OnClick =Button4_Click
style =z-index:1; left:185px; top:2840px; position:absolute; height:30px; width:80px; font-size:largeForeColor =Green
Text =SubmitOnClientClick =DisableButton();/>
假设您需要执行一次Button4_Click()处理程序然后禁用提交按钮,尝试删除java脚本代码并尝试如下。
添加代码以在提交按钮处理程序结束时禁用;
受保护 void Button4_Click(<温泉n class =code-keyword> object sender,EventArgs e)
{
// 您提交处理程序代码
// .....
// ....
Button4.Enabled = false ; <预> // 首次执行后禁用
}
document.getElementById('<%= this.button.ClientID%>')。disabled = false;
Using the following codes I am unable to disable the 'Submit' btn after a click.
<head runat="server">
<title>Untitled Page</title>
<script type = "text/javascript">
function DisableButton() {
document.getElementById("<%=Button4.ClientID %>").disabled = true;
}
window.onbeforeunload = DisableButton;
</script>
<asp:Button ID="Button4" runat="server" ToolTip="Please note down your member ID for future reference"
OnClick="Button4_Click"
style="z-index: 1; left: 185px; top: 2840px; position: absolute; height:30px; width:80px; font-size:large " ForeColor="Green" Text="Submit" />
解决方案
Use this javascript code
<script type="text/javascript" language="JavaScript"> function DisableButton() { document.getElementById("<%=Button4.ClientID %>").disabled = true; } </script>
After this Add [OnClientClick] attribute to control
<asp:Button ID="Button4" runat="server" ToolTip="Please note down your member ID for future reference" OnClick="Button4_Click" style="z-index: 1; left: 185px; top: 2840px; position: absolute; height:30px; width:80px; font-size:large " ForeColor="Green" Text="Submit" OnClientClick="DisableButton();"/>
Assuming you need Button4_Click() handler executed once and then disable the submit button,try removing the java script code and try as below .
Add code to disable at the end of submit button handler;
protected void Button4_Click(object sender, EventArgs e) { //you submit handler code //..... //.... Button4.Enabled = false; <pre> //disable after first execution }
document.getElementById('<%= this.button.ClientID %>').disabled = false;
这篇关于如何禁用提交按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文