Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I a have a ASP.NET panel, In which, I placed two buttons Submit and Cancel. I configured Submit as Default button, which works well. But when I hit enter key on Cancel button it also submit my page.

Please help me overcome this....
Posted
Updated 26-Dec-13 3:37am
v3
Comments
Can you post the code and clarify more.
Kapil Nandgave 26-Dec-13 9:29am    
hi i have used asp panel in which i take two buuton btn1 and btn2 how to set default button for only one buttton not for other
See my answer Solution 2. :)
Karthik_Mahalingam 26-Dec-13 9:10am    
popup panel or what it is ?
add more information..
Kapil Nandgave 26-Dec-13 9:27am    
please tell me how to set default buttton for only one button

 
Share this answer
 
Comments
Sampath Lokuge 26-Dec-13 10:17am    
+5,This should work.
Thanks a lot Sampath Lokuge. :)
JoCodes 26-Dec-13 10:30am    
Nice one Tadit...
Thanks JoCodes. :)
Are you saying that when the Cancel button has focus and you hit Enter it clicks the Cancel button? If so, there is nothing you can do about that unless you perhaps want to use JavaScript to track every key press which is not a good idea.
 
Share this answer
 
You can use
Panel.Defaultbutton
set to the Submit button as Tadit's suggestion.
One more thing you should consider is the setting of Defaultbutton doesn't guarantee only the Submit button is fired when user clicks Enter Key since the behavior is such that when the focus is on other buttons pressing Enter will fire that button instead of default one.

So try to also add a
UseSubmitBehavior="false"
for Cancel button to avoid such behavior.
 
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