Javascript

JavaScript to disable button after click

<script language=”javascript” type=”text/javascript”>
function disableButton(sender,group)
{
Page_ClientValidate(group);
if (Page_IsValid)
{
sender.disabled = “disabled”;
__doPostBack(sender.name, ”);
}
}
</script>

and in Html

<div>
Enter Name :-
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
<asp:RequiredFieldValidator ID=”RequiredFieldValidator1″ runat=”server” ControlToValidate=”TextBox1″
ErrorMessage=”RequiredFieldValidator”>*</asp:RequiredFieldValidator><br />
<asp:Button runat=”server” ID=”btnSave” Text=”Save” OnClick=”Save” OnClientClick=”disableButton(this,”)” UseSubmitBehavior=”false” />
</div>

If there is Validation Group it will be like this :-

Add this Javascript code :-

<script language=”javascript” type=”text/javascript”>
function disableButton(sender,group)
{
Page_ClientValidate(group);
if (Page_IsValid)
{
sender.disabled = “disabled”;
__doPostBack(sender.name, ”);
}
}
</script>

and HTML will be :-

<div>
Enter Name :-
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
<asp:RequiredFieldValidator ID=”RequiredFieldValidator1″ runat=”server” ControlToValidate=”TextBox1″ ValidationGroup=”i”
ErrorMessage=”RequiredFieldValidator”>*</asp:RequiredFieldValidator>&nbsp;<br />
<asp:Button runat=”server” ID=”btnSave” Text=”Save” OnClick=”Save” OnClientClick=”disableButton(this,’i’)” UseSubmitBehavior=”false” ValidationGroup=”i” />
</div>

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.