CJ

The circle of life – ** .Net – Training – MOSS **

  • Past Post

  • Vistor Locations

Update Panel and Default Button fix

Posted by Clayton James 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;
}

Advertisements

8 Responses to “Update Panel and Default Button fix”

  1. NVP said

    Thanx a lot….

  2. VKP said

    Nice one man, Keep continue,

  3. Sai Kakarlamudi said

    Thanks a ton. Great work!!!

  4. 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

  5. Sebastian said

    Perfect ! Very Good ! Thanks a lot

  6. Jefferson Santos said

    Thank you. Congratulations. You saved my life.

  7. hundreder said

    I’ve managed this to work only by setting __defaultFired = undefined;

  8. Haha, so hold it arms length away and do a complete home remodeling that
    will redecorate my house anew. Rnd 6: Sc in next sc,
    2 sc in 2nd ch from hook.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: