Monday, April 27, 2009

mozilla frefox enter button problem in asp.net.

i am facing a small problem, which ate my mind almost 10 hours.
Introduction:
I am using Updatepanel [Ajax] in my site. According to my client specification, in which panel or div cursor focus on, when he/her press enter, the corresponding panel button click event will fire and request goes to server and gives response.
i am using control on my pages, because it has the property called DefaultButton. So, this will work perfectly for me if and only if, user browse my site in IE. then what about Mozilla?
Here my problem starts…
Problem:
1. The DefaultButton property of the Panel/Form won’t work in Mozilla when you hit enter key, when all these panels are reside in UpdatePanel control.
2. When any one press Enter button, it should check for validation if any input controls are there in that panel.
Solution:
After a long research i wrote small java script function to solve the problem.
OnClientClick=”setDefaultButton(this.name);
Java script function:
function setDefaultButton(name)
{
Page_ClientValidate();
if(document.all)
{}
else
{
if(!Page_IsValid)
__doPostBack(name,"");
}
}
if you have any issues with my code, please let me know.

No comments:

Post a Comment