Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1185
ValueChange not firing in Firefox?
posted

I have a series of WebtextBox controls which fire ValueChange client events so I can maintain some subtotals on scren as the user enteres data.

This works fine in IE, but the client events are not firing in Firefox at all. The same event on a webCombo is working well, it just seems to be the WebTextEditor control?

is this a bug?

Parents
No Data
Reply
  • 1185
    Verified Answer
    posted

    Ahh, i tracked this one down. Its an example of when not to cut/paste code from samples online without testing...sigh.It wasn't an event problem, but an incompatability between IE's and Firefox's DOM implementations.

    The core issue was trying to update some <asp:label> controls with subtotals, and discovering that the most common solution discussed on the web: innerText, doesn't work consistently. That is, to retrieve the value in an asp:Label control, you typically use:

    var test = document.getElementById('<%=txtBaseline2.ClientID%>').innerText;

    which works in IE, but will fail in Firefox because the innertext property doesn't exist there. Tt has a textContent property instead.

    Thus any part of your code that has to manipulate labels (ie: any values you don't want a user manipulating directly), you need to replace direct access to document.getElementById with functions such as:

            function getLabelText(LabelID) {
                // required to work around differences between IE and Firefox...
                if (document.all)
                    // IE
                    return document.getElementById(LabelID).innerText;
                 else
                    // Firefox
                    return document.getElementById(LabelID).textContent;
            }

            function setLabelText(LabelID, value) {
                if (document.all)
                    document.getElementById(LabelID).innerText = value;
                else
                    document.getElementById(LabelID).textContent = value;
            }

    You call them as follows:

    getLabelText('<%=txtHeadSub3.ClientID%>')

    or

    setLabelText('<%=txtHeadSub3.ClientID%>', "Some Value");

    Your code is then operation using both firefox and IE. Note that other solutions exist using pure DOM as well, which may be necessary if implementations of pseudo standards change yet again...

Children