Update Panel and Default Button fix
Posted by CJ on July 7, 2008
Here is a workaround (hack) to fix the default button on a form that is enclosed inside an update panel.
Add the following to the .aspx page.
function ResetDefaultFired()
{
__defaultFired = false;
}
Add the following property to each button that is enclosed inside the update panel
OnClientClick=”ResetDefaultFired”
Blurb from msdn forum
The problem is in the used javascript to handle the default button in combination with Atlas.
When a default button is set in a Panel the following attribute is rendered:
onkeypress = “Javascript:return WebForm_FireDefaultButton(event, ‘[buttonId]‘);”If you look at the code of WebForm_FireDefaultButton you will see a variable ‘__defaultFired’.This variable is used to just fire the event only 1 time in a roundtrip cycle. After you hit the enter key this variable is set to true. Because atlas is updating just a part of the screen this variable won’t be reset to false. So the second time you hit enter nothing happens or the default behavior of the browser is taking place (firing the first submit button on the screen in IE)
code snippet of the javascript WebForm_FireDefaultButton function
var __defaultFired = false;
function WebForm_FireDefaultButton(event, defaultButton) {
if (!__defaultFired && event.keyCode == 13) {
if (__nonMSDOMBrowser) {
src = event.target;
}
else {
src = event.srcElement;
}
tagName = src.tagName.toLowerCase();
if ((tagName != “a”) && ((tagName != “input”) || ((src.type != “submit”) && (src.type != “reset”) && (src.type != “image”) && (src.type != “file”)))) {
if (defaultButton.click != “undefined”) {
__defaultFired = true;
defaultButton.click();
if (__nonMSDOMBrowser) {
event.cancelBubble = true;
}
return false;
}
}
}
return true;
}
NVP said
Thanx a lot….
VKP said
Nice one man, Keep continue,
Sai Kakarlamudi said
Thanks a ton. Great work!!!
Muhammad Awais said
Thanks a lot buddy. you have solved my problem. i was quite confused with this issue from two weeks. now its working perfectly. thanks a lot. keep continue with such solutions greatttttttttt
Sebastian said
Perfect ! Very Good ! Thanks a lot