Click here to Skip to main content
15,896,304 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using the following codes I am unable to disable the 'Submit' btn after a click.

XML
<head runat="server">
    <title>Untitled Page</title>
    <script type = "text/javascript">
        function DisableButton() {
            document.getElementById("<%=Button4.ClientID %>").disabled = true;
        }
        window.onbeforeunload = DisableButton;
</script>


CSS
<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" />
Posted

Use this javascript code

XML
<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();"/>
 
Share this answer
 
Comments
S.Rajendran from Coimbatore 13-Nov-14 3:39am    
I tried with your code but the first click itself is disabled. I need first click to be effected and further clicks should be disabled.
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;

C#
protected void Button4_Click(object sender, EventArgs e)
{
    //you submit handler code
    //.....
    //....

    Button4.Enabled = false; <pre> //disable after first execution
   
}
 
Share this answer
 
document.getElementById('<%= this.button.ClientID %>').disabled = false;
 
Share this answer
 
Your code have one minor error.Refer below code ......

XML
<head runat="server">
    <title>Untitled Page</title>
    <script type = "text/javascript">
        function DisableButton() {
            document.getElementById("Button4").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" />
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900