Click here to Skip to main content
15,909,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey there,

I have a submit button and I want to validate it so that it does not show exception when there is no data to submit in the data table and maybe show an alert or message like "please select an item!".

Also want to know how can I disable a button.

Thanks
Amit
Posted
Updated 15-Sep-10 3:40am
v2
Comments
Dalek Dave 15-Sep-10 9:40am    
Edited for Grammar.

This answer is for disable a button

You can keep a image and the button in the same div tag. Initially, make the
button visible and the image invisible. And when the user clicks the button
then hide the button and make the image visible. So in this situation user
will not be able to click the button twice and your problem will get solved.
 
Share this answer
 
Comments
AmitChoudhary10 15-Sep-10 7:33am    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
AmitChoudhary10 15-Sep-10 7:41am    
But its not an image button,its a simple asp.net button and also i want to use some validations or alert.
Dalek Dave 15-Sep-10 9:40am    
Good Answer.
say for example your button id is btnSubmit
and the name of the datatable is dtTestTable then the code in the code behind will be
if(dtTestTable != null )
{
  btnSubmit.CausesValidation = false; 
}
else
{
  btnSubmit.CausesValidation = true;
}


cheers... :)
if this solves your problem mark it as answered
 
Share this answer
 
Comments
AmitChoudhary10 15-Sep-10 8:14am    
and i'll be using this with requiredField validator?...
senguptaamlan 15-Sep-10 8:16am    
yeah right...
AmitChoudhary10 15-Sep-10 8:22am    
its showing error

Control 'btnSubmit' referenced by the ControlToValidate property of 'rvSubmit' cannot be validated.
senguptaamlan 15-Sep-10 8:25am    
what is rvSubmit?
AmitChoudhary10 15-Sep-10 8:25am    
id required field validator for btnSubmit
 
Share this answer
 
Comments
Dalek Dave 15-Sep-10 10:05am    
Good Link.
This answer is for required validations.
drag required validator control in tool box and put into corresponding validating control.(text box)
steps to do ,
control to validate:which control(ie,text box )
error message :whatever you displaying message clicking submit button
 
Share this answer
 
Comments
AmitChoudhary10 15-Sep-10 7:45am    
Okay but i don't think i can use it for something like when a datatable is null or a gridview is null.can i?...
Ashika s 15-Sep-10 8:02am    
recquired field validator is using for validating controls.
for data table ,using this if(datatable.rows.count>0)
aayu 15-Sep-10 8:26am    
aur if you want to put your condition then u can use custom validating

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