Force ASP.NET to generate JavaScript for all User Agents
Asked Answered
C

1

8

I noticed recently in my ASP.NET web application that if I set my User Agent to an empty string (using a FireFox plug-in to spoof the user agent), then ASP.NET will not generate the javascript required to perform postbacks. More specifically, if you try calling the __doPostBack(a, b) function from your javascript, you will get an error saying that function is undefined.

I understand that every browser has a user agent, so this won't come up that often, but the essence of the problem still exists: there are cases in which an unrecognized or malformed user agent can render your web application unusable if you rely on postbacks.

This is similar to this question: ASP.net not generating javascript for some User Agents, but if I'm reading it right it looks like you'd fix each unrecognized user agent case by case and mask it as another browser. My concern is less with an individual user agent, and more so with the overall fact that certain user agents won't be able to use my application and I won't know it because the error happens in javascript and not on the server.

Does anyone know of a way that I can force ASP.NET to always generate the required javascript?

Cambridgeshire answered 24/12, 2012 at 21:52 Comment(9)
Have your users actually encountered this problem? If not, then I would ask if there are other problems your users have actually encountered.Spinoff
@John - No one has reported it, but our web app deals with ecommerce so the average user that experiences an issue wouldn't usually go through the trouble of contacting us, they'd just move on to the competitor's site. We also just launched a mobile store which invites an entirely new league of possible user agents and I'd like to avoid as many issues as possible.Cambridgeshire
I hope you're logging your unhandled exceptions, then. Otherwise, you're in danger of spending time fixing problems your customers are not experiencing, while your competitors spend their time improving their site.Spinoff
@John - We have our unhandled exceptions under control and fix problems as they come. So far nothing you have said has actually addressed my question.Cambridgeshire
@Cambridgeshire I agree with John. Only make update the user agent for avoid issues like IE 10, but not change the default behavior for the default browser.Chalutz
@Chalutz - I can see that side of it. If that's what John meant and I misunderstood then I apologize. I felt though that John was saying "don't worry about it", and I don't feel that's constructive on a Q&A website. You're point, however, is constructive, so thank you very much.Cambridgeshire
@Adam: I do mean "worry about real problems before imagined problems", but also, "make sure you find out about all real problems ASAP so you can worry about them".Spinoff
@JohnSaunders - We do log our unhandled exceptions, and we do resolve them as they come in, ASAP. Due to the recent release of the mobile version of our web app, my concern is not necessarily that someone with an empty user agent string will use the app, but rather that with the wide array of mobile devices and the obscure browsers that can be installed on them, some users will have an unrecognized user agent and won't receive the javascript needed to run the app. A similar issue has happened with IE10 and that's not even obscure.Cambridgeshire
@JohnSaunders - Btw, you do make some good points. And I am taking that into account. Bottom line, I'm just looking for an answer to this, regardless of how widespread the issue it.Cambridgeshire
C
4

If you set empty to the User Agent, or if you use an unknown User Agent string, then asp.net reads the Default.browser file from Browsers directories and there you can define how to you like to act on this cases.

The lines that you need to change and on this cases use javascript is that ones:

        <capability name="jscriptversion"       value="5.6" />
        <capability name="javascript"           value="true" />
        <capability name="javascriptversion"    value="1.5" />

on the default, the javascript line if false. I like to comment here that I am not so sure if you really need to change it, if some one spoof the user agent, let it do it. If he likes your site and need to use it, then is better let you know how to handle the browser that he use. From the other hand you must take care if this is possible, your site to work even with out javascript, at least for most of the actions you do.

Is better to avoid link buttons (that use the _doPostBack) and use post back buttons for example. I know that GridView and other use also the _doPostBack for paging... ok with that, but is better one good site to been able to work even with out javascript.

Some similar question:
__doPostBack is undefined on DotNetNuke website for IE 10

and this blog: Bug and Fix: ASP.NET fails to detect IE10 causing _doPostBack is undefined JavaScript error or maintain FF5 scrollbar position

Chalutz answered 24/12, 2012 at 22:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.