views:

206

answers:

2

The following code is being used to disable a Submit button once it has been clicked. This works great on desktop browsers and most BlackBerry mobile browsers.

Submit.Attributes.Add("onclick", "javascript:this.disabled=true;" +
    ClientScript.GetPostBackEventReference(Submit, null));

Unfortunately, when using a BlackBerry Storm clicking the submit button causes the device to just reload the page. If I remove this code the Storm browser submits the page just fine. I need to disable the button when the browser is capable of doing so but do not want to affect browsers that are not JavaScript capable.

I realize I could add the jQuery framework and only attach the event client side, but am trying to look for the simplest fix (read least intrusive) as this is a legacy application. Any suggestions?

+1  A: 

I believe you can do it this way - I haven't done this in a long time and some of the HttpCapabilities API has been tagged as obsolete, but in general you can detect if the browser supports javascript by doing this:

    var myBrowserCaps = Request.Browser;
    if (((HttpCapabilitiesBase)myBrowserCaps).EcmaScriptVersion.Major > 1)
    {
        // Browser supports javascript
        Submit.Attributes.Add("onclick", "javascript:this.disabled=true;" +
                    ClientScript.GetPostBackEventReference(Submit, null));
    }
womp
@Womp that looks good excet rather than `HttpCapabilitiesBase` I used `HttpBrowserCapabilities`. Thank you for the help and sorry for my delay in testing your suggestion. I was AFK for 10 days. ;)
ahsteele
A: 

Have you tried adding 'return false;' at the end of the onclick javascript code? Maybe the disable has the same effect on most browser, but not on the BlackBerry.

ADB