Search code examples
javascriptasp.netanchormozillabroken-links

Mozilla gets strange value in WebForm_DoPostBackWithOptions JavaScript function


  1. Where does the variable options.eventTarget come from?
  2. How can I fix this function for Mozilla if it's generated by ASP.NET code?
  3. What is this JavaScript function used for?

Mozilla Firefox gets this value for options.eventTarget at the end of this function when the anchor tag is called. The Save (anchor tag) button doesn't work in Mozilla, so I'm trying to figure out why.

ExplorerPageHtmlLeft$ct...aveCancelDelete$LBuSave <===== problem

Internet Explorer gets this value for options.eventTarget at the end of this function when the anchor tag is called. The Save (anchor tag) button works fine in Internet Explorer.

ExplorerPageHtmlLeft$ctl02$ctl00$SaveCancelDelete$LBuSave

Here is the code spread out so it's easy to read


Mozilla Firefox Save button (broken):

<a
id="ExplorerPageHtmlLeft_ctl02_ctl00_SaveCancelDelete_LBuSave"
href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ExplorerPageHtmlLeft$ctl02$ctl00$SaveCancelDelete$LBuSave", "", true, "", "", false, true))"
onclick="javascript:encryptField(document.getElementById('ExplorerPageHtmlLeft_ctl02_ctl00_SaveCancelDelete_TxtPassword'),document.getElementById('IHHidden'));"
>
<img border="0" alt="Save" src="/images/save.gif">
</a>

Internet Explorer Save button (works fine):

<a
onclick="javascript:encryptField(document.getElementById('ExplorerPageHtmlLeft_ctl02_ctl00_SaveCancelDelete_TxtPassword'),document.getElementById('IHHidden'));"
id="ExplorerPageHtmlLeft_ctl02_ctl00_SaveCancelDelete_LBuSave"
href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ExplorerPageHtmlLeft$ctl02$ctl00$SaveCancelDelete$LBuSave&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))"
>
<img src="/images/save.gif" border="0" alt="Save">
</a>

Here is the JavaScript function:

function WebForm_DoPostBackWithOptions(options) {
    var validationResult = true;
    if (options.validation) {
        if (typeof(Page_ClientValidate) == 'function') {
            validationResult = Page_ClientValidate(options.validationGroup);
        }
    }
    if (validationResult) {
        if ((typeof(options.actionUrl) != "undefined") && (options.actionUrl != null) && (options.actionUrl.length > 0)) {
            theForm.action = options.actionUrl;
        }
        if (options.trackFocus) {
            var lastFocus = theForm.elements["__LASTFOCUS"];
            if ((typeof(lastFocus) != "undefined") && (lastFocus != null)) {
                if (typeof(document.activeElement) == "undefined") {
                    lastFocus.value = options.eventTarget;
                }
                else {
                    var active = document.activeElement;
                    if ((typeof(active) != "undefined") && (active != null)) {
                        if ((typeof(active.id) != "undefined") && (active.id != null) && (active.id.length > 0)) {
                            lastFocus.value = active.id;
                        }
                        else if (typeof(active.name) != "undefined") {
                            lastFocus.value = active.name;
                        }
                    }
                }
            }
        }
    }
    if (options.clientSubmit) {
        __doPostBack(**options.eventTarget**, options.eventArgument);
    }
}

Solution

  • Well, it appears that the value of the options.eventTarget is not the issue at all. It was strange that it was exactly exactly 50 characters.

    options.eventTarget in Firebug: "ExplorerPageHtmlLeft$ct...aveCancelDelete$LBuSave"

    It turns out that Mozilla Firefox Firebug only shows 50 characters.. it takes the first and last part of the control client ID (and the 3 dots in the middle) and sticks that into the value field within the Firebug watch variable. To confirm, I just put "alert(options.eventTarget)" into the watch variable, and it showed the entire value. So that definitely isn't it!

    I still have no idea why my LinkButton doesn't call my event handler in my code behind in Mozilla, but it does in Internet Explorer. I guess once I have more information, I will post it (probably on a different question). It might have something to do with having validation turned on when my link button is clicked. That's what causes ASP.NET to put this function into the client code automatically I guess.