Click here to Skip to main content
15,885,025 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi there,

How can I disable Submit button after first click. I used the below code. It works fine if there is no Asp.net validators. If any entry doesn't match the validation too, the Submit button goes invisible. I just want to make the button invisible after all validations...

btnSubmit.Attributes.Add("onclick", "this.style.display='none';");

Thanks in advance
Posted
Updated 9-Oct-20 1:21am
v2
Comments
sabbi26 18-Oct-11 8:09am    
Better to write a server side event for the button and in that u make it as disabled.
[no name] 18-Oct-11 8:15am    
Why is this better?
aswathy.s.88 19-Oct-11 0:26am    
I don't think it is that easy to do with Server side....
plllplplpl 23-May-12 8:12am    
why we can not set in client side?

function onSubmit()
{
   if(Page_Validate())
   ...or...
   if(Page_Validate("Validation group name"))
   {
      $("#submit").hide();
   }
}
 
Share this answer
 
if (!Page.IsPostBack)
{

 btnSubmit.Attributes.Add("onclick", "javascript: if (Page_ClientValidate() ){" + btnSubmit.ClientID + ".disabled=true;}" + ClientScript.GetPostBackEventReference(btnSubmit, ""));
}
 
Share this answer
 
v2
Comments
[no name] 19-Oct-11 22:29pm    
Completely unnecessary and cumbersome to implement in code-behind. Learn to use JQuery
You can implement it via Java script or use click event of button to disable it. Don't forget to chech isPostBack in page load function.
 
Share this answer
 
Why dont u go for server side coding
in the event of btn_click()
u can write
VB
btn.Enabled=False
 
Share this answer
 
Comments
aswathy.s.88 19-Oct-11 2:16am    
No... it doesn't work ....

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