Andy Smith's Blog

Page.RegisterStartupScript('Andy', 'MetaBuilders_WebControls_GainKnowledge();');

Firefox nonbug that caused me some grief today

I ran into a rather unfortunate issue today with a server control that I thought would probably be good to talk about. The issue is created by non-bugs that come together to make a bug.

  • Firefox persists the values of form fields when the user refreshes the page.
  • Firefox does not persist any script objects applied to the document or the window
  • Complex server controls will commonly use script objects for the lifetime of the page, and use hidden inputs to round trip values from server to client to server.

So this is the result of these 3 items...

  • A user with firefox hits your page with your control on it the first time...
  • Your initialization script runs, and all script objects and hidden inputs are in the initialized state.
  • The user plays with the page a bit, and your control changes its state, changing object properties and hidden input values.
  • The user hits refresh in their browser. Firefox nullifies all script objects, but retains the values of the hidden inputs.
  • Your control's initialization runs again, but now the script objects are created with hidden input state that is not the original.

Now, as you can imagine, this has a very high possibility of completely borking your control. Now, before I get flames, let me restate that I don't consider this a bug in Firefox. It's just a behavior that I hadn't planned for. However, ultimately, it has a way of changing my methods for roundtripping values between client and server.

For now, my best solution is to include any "initial" values in the RegisterArrayDeclaration call for the control, while previously i would normally only put them in the hidden input.

Comments

AndrewSeven said:

Non-bug?
It seems to me that when the user refreshes the page, the browser should either return to the server and get a new version or serve the version that was in its cache. In either case, there should be no state leaking from the previous page to the current page.

I completely fail to understand how serving a cached version with modified state is a refresh. It seems to take us back to needing to set explicit and immediate expiration of any html served to FF. OnResize=>Reload?
# July 14, 2004 6:59 PM

Michael K. Campbell said:

I'd have to agree with Andrew. If you do hit a refresh it seems the page should be reloaded.
Granted, it's a pain to lose all of the form info that you just entered, so I can see why the FF folks tried to do something sneaky to preserve that. The fact that they're thinking about browsing wins them points in my book. That being said... it seems that a better way to achieve the functionality that they're trying to do would be:
1) Reload the page from the server.
2) An alert (that you could configure to auto yes|no) asks: would you like to repopulate form fields?
The idea being that it would use some sort of mapping of form fields (though wouldn't tweak HIDDDEN fields) that it used on a page by page basis (kind of like a customized per page version of those nasty wallet apps that 'remember' your account info from site to site).

Anyhow... that's just my thought.

Thanks for posting about this though Andy, this will be a lifesaver for me down the road.
# July 15, 2004 12:35 AM

Frans Bouma said:

I've had exactly the same behavior with an ASP site and I couldn't figure out why a form submit on the server did a complete different thing than with IE. Thanks for the update :)
# July 15, 2004 4:31 AM

Todd Moon said:

Very interesting. Good sleuthing!
# July 15, 2004 9:20 AM

Daniel Cazzulino said:

This is one of the features of FireFox I love the most, specially when I'm forced to do something with malfunctioning sites as GDN, for example. I hate when IE loses my input upon refreshing. This is something what should be the standard, not the exception.
The other feature I love is that it retains the scroll position automatically. So if I perform a postback, IE will take me back to the top of the page, whereas FireFox won't. You see, now you have the ASP.NET team adding this "feature" to ASP.NET v2 when it's actually more of a bug fix for the oldest browser people use.
Whatever...
# July 16, 2004 8:26 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)