Page view counter

Validation controls not working in FireFox (migrating from 1.1 to 2.0)

Last post 07-09-2008 10:39 AM by Naom. 4 replies.

Sort Posts:

  • Validation controls not working in FireFox (migrating from 1.1 to 2.0)

    07-01-2008, 7:07 PM
    • Loading...
    • CodeDummy
    • Joined on 07-01-2008, 10:29 PM
    • Posts 3
    • Points 0

    Hello All,

    I'm wondering if anyone has run into this specific problem. I've migrated a legacy VS2003 web project into VS2005. I've managed to compile the code after making some slight adjustments (for example, I now make a reference to System.Configuration instead of System so that I can use the newer ConfigurationManager class). I can run the code and bring up my login page which then brings me to another page to input some data.

    The problem is that the asp.net validation controls do not work in FireFox. The reason why we migrated was that the original WebUIValidation.js script had bugs so that the controls only worked in IE. You were out of luck in FireFox. I had read on a post somewhere that this issue was resolved in VS2005. So hence our migration ... however the results are identical ... They work in IE but not in FireFox. The strange thing is that when I create a new Web page and place textbox and validators on that page, they work in FireFox. But the legacy implementation is not as simple as that.

    The payment page (Payment.aspx) begins by loading a "Coupon" control (CouponControl.acsx) that contains text boxes with the associated CustomValidator, RequiredFieldValidator, and RegularExpressionValidators.

     The control successfully loads the text boxes and buttons. Text is entered (in FireFox) and nothing happens. In IE, the validation works fine. It seems odd but the behavior of the legacy pages seem to be using the old WebUIValidation.js script while the newly created page will used the embedded resource version?!?!?

     Any help/ideas would be greatly appreciated.

     Gary

     

     

  • Re: Validation controls not working in FireFox (migrating from 1.1 to 2.0)

    07-01-2008, 8:31 PM
    • Loading...
    • lrd.morpheus
    • Joined on 06-29-2008, 2:45 AM
    • Posts 16
    • Points 82

    I've recentllly finished a big migration from Fw 1.1 to Fw 2.0 with no problems at all, and the validator controls are working like a charm. You should install the Firebug add-on for Firefox to check what's really going on in your js. It's a breeze to use (sadly unlike ms tools) and it's very usefull debugging CSS and network request / posts as well.

  • Re: Validation controls not working in FireFox (migrating from 1.1 to 2.0)

    07-01-2008, 8:53 PM
    • Loading...
    • CodeDummy
    • Joined on 07-01-2008, 10:29 PM
    • Posts 3
    • Points 0

    I'll give it a try. Im starting to suspect that it's the way the controls are being loaded onto the page. Maybe the link to the resource is getting dropped along the way.

  • Re: Validation controls not working in FireFox (migrating from 1.1 to 2.0)

    07-02-2008, 2:14 PM
    Answer
    • Loading...
    • CodeDummy
    • Joined on 07-01-2008, 10:29 PM
    • Posts 3
    • Points 0

    Issue is fixed. In my Web.Config file, remove this line:

    <xhtmlConformance mode="Legacy"/>

     Here is a link to a URL that talks about this issue:

     http://aspadvice.com/blogs/rbirkby/archive/2006/11/01/Client_2D00_side-validation-in-Firefox.aspx

     Here is the text just in case the site goes away. After installing FireBug, I noticed that the code where page validators were being assigned to the array was being commented out at the bottom of the page. Looking at this article, I noticed a similarity (I have highlighted the code below) in the way the code was being commented out ALSO at the bottom of the example page.

     ******************************************************************************************************

     Recently, I was faced with a problem whereby client-side validation of controls failed to work in Firefox. Only server-side validation was working. Client side validation was working fine in IE.

    This was puzzling as everything I read said that ASP.Net v2 supported client-side validation in Firefox. No amount of Googling helped to identify the problem, so I had to track it down from scratch - and the results were quite interesting. If you have

    <xhtmlConformance mode="Legacy"/>

    set in your web.config, then client-side validation is disabled in firefox.

    To see why, we have to jump down into the validation framework that ASP.Net sends to the web browser. The actual Javascript validation function looks like:

    function ValidatorValidate(val) {

          val.isvalid = true;

          if (val.enabled != false) {

                if (typeof(val.evaluationfunction) == "function") {

                      val.isvalid = val.evaluationfunction(val);

                }

          }

          ValidatorUpdateDisplay(val);

    }

    Using Venkman, I was able to see that val.evaluationfunction wasn't a function at all, therefore the page wasn't getting validated because of this. A bit more searching found that this evaluationfunction is an expando attribute. In ASP.Net v1, this expando is an IE-only HTML expando, defined directly in the HTML markup. In ASP.Net v2, this is a Javascript expando attribute, defined on the DOM via Javascript, and therefore compatible with both IE and Firefox.

    For example, the RequiredFieldValidator calls RegisterExpandoAttribute. You can call this method yourself like:


    Page.ClientScript.RegisterExpandoAttribute(TextBox1.ClientID, "value", TextBox1.Text);

     This produces a block of Javascript just before the closing </form> tag like:


    <script type="text/javascript">

    <!--

    var TextBox1 = document.all ? document.all["TextBox1"] : document.getElementById("TextBox1");

    TextBox1.value = "";

    // -->

    </script>

    where "value" has become the new expando attribute. In the case of the RequiredFieldValidator, the expando name is" evaluationfunction" and it is added to the <span> representing the control at runtime.


    It turned out that this block of Javascript wasn't being sent to Firefox in my situation, and I didn't know why. Instead, the evaluationfunction expando attribute was being rendered directly on the <span> element in HTML.


    So after good deal of decompilation using Reflector, and debugging using Reflection Invokeing of private methods, I discovered the problem was that RegisterExpandoAttribute checks the XHTML Rendering Mode prior to generating the Javascript and if that rendering mode is set to Legacy, then the expando is rendered directly onto the <span> element and no Javascript code is rendered. The result of this is to prevent Firefox from performing client-side validation when Legacy XHTML mode is set.


    I have no idea why the ASP.Net team chose to do this for validation. Perhaps the Legacy XHTML setting should have been called "ASPNetv1Conformance" because that's actually what it does. The docs for Legacy mode state:


    "Reverts a number of rendering changes made for conformance to the v1.1 rendering behavior."

     

     

     

     

  • Re: Validation controls not working in FireFox (migrating from 1.1 to 2.0)

    07-09-2008, 10:39 AM
    • Loading...
    • Naom
    • Joined on 12-31-2007, 2:08 PM
    • Wisconsin
    • Posts 4,426
    • Points 18,995

    Interesting, let me see if this applies in my case, because I ran into the same issue. Yes, I found exactly the same line in my web.config.

    Thank you so much for your post. 

     

    Beware of bugs in the above code; I have only proved it correct, not tried it.
    (Donald Knuth)
Page 1 of 1 (5 items)