ASP.net does not generate javascript for some user agents

******************** Edit 2 *********************** I understand the problem ... But I do not like the consequences. I previously tested the mobile app for iPhone using the Firefox User Agent String masking plugin as an iPhone.

.Net was infact NOT, generating the required code for post backs based on only this piece of information.

I don't like this because, because iPhone and other multimedia devices can interpret javascript, ASP.net breaks any application based on the javascript server running.

So, if the community resolves this ... I would like to change my official question ... Why won't ASP.net generate javascript for specific browsers and how can I disable this feature?

*************** End Edit 2 ***************

I have a strange problem. I copied some working code from my remote host to my computer at work. When I try to use the page, I get javascript error

__doPostBack is not defined javascript:__doPostBack('ctl00$ContentPlaceHolder1$login','')()() 

When the source of the output page is not enough for me, I am sure that no javascript has been created on the server side.

I tried to create a simple page:

 <%@ Page Language="VB" AutoEventWireup="false" CodeFile="jsTest.aspx.vb" Inherits="_jsTest" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:TextBox ID="tbTest" runat="server"></asp:TextBox><br /> <asp:LinkButton ID="linkTest" runat="server">LinkButton</asp:LinkButton> </form> </body> </html> 

Codebehind:

 Partial Class _jsTest Inherits System.Web.UI.Page Protected Sub linkTest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles linkTest.Click Response.Write(tbTest.Text) End Sub End Class 

Getting the same error.

I tried rebooting (hey, it works a half times), cleared everything from App_Code, global.asax and web.config, added a text box with autopostback = true ... I have no ideas.

Can anyone shed light on what is happening here?

************** Additional information *************** I just tried everything in IE, and it works as expected, shows the page source:

 <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /> <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTkxNTA2MDE2NWRkxhZMwlMVwJprcVsvQLJLrTcgaSM=" /> <script type="text/javascript"> //<![CDATA[ var theForm = document.forms['form1']; if (!theForm) { theForm = document.form1; } function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } //]]> </script> <div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwK20LZAAuzRsusGAsz0+6YPxxO+Ewv1XsD5QKJiiprrGp+9a3Q=" /> </div> 

So far, the source in Firefox only shows:

 <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTkxNTA2MDE2NWRkxhZMwlMVwJprcVsvQLJLrTcgaSM=" /> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwK20LZAAuzRsusGAsz0+6YPxxO+Ewv1XsD5QKJiiprrGp+9a3Q=" /> 

Saving web pages to the desktop and opening in notepad show the same thing ...

+5
javascript user-agent auto-generate
source share
6 answers

The problem is that ASP.net belongs to unknown browsers ... for example, to the iPhone. Although it would be nice to assume that unknown browsers might use javascript ... you can specify what features the browser has in the web.config or machine.config section.

Check out the http://slingfive.com/pages/code/browserCaps/ updated browser configuration file for asp.net

Here is an example case for matching GECKO-based browsers (Netscape 6+, Mozilla / Firefox, ...)

 <case match="^Mozilla/5\.0 \([^)]*\) (Gecko/[-\d]+)(?'VendorProductToken' (?'type'[^/\d]*)([\d]*)/(?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'\w*)))?"> browser=Gecko <filter> <case match="(Gecko/[-\d]+)(?'VendorProductToken' (?'type'[^/\d]*)([\d]*)/(?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'\w*)))"> type=${type} </case> <case> <!-- plain Mozilla if no VendorProductToken found --> type=Mozilla </case> </filter> frames=true tables=true cookies=true javascript=true javaapplets=true ecmascriptversion=1.5 w3cdomversion=1.0 css1=true css2=true xml=true tagwriter=System.Web.UI.HtmlTextWriter <case match="rv:(?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'\w*))"> version=${version} majorversion=0${major} minorversion=0${minor} <case match="^b" with="${letters}"> beta=true </case> </case> </case> 
+7
source share

Before reinstalling Firefox, run it in debug mode (I think it's called debug mode). It disables all plugins, and this can help you narrow it down a bit. What about other browsers like Chrome or Safari?

+2
source share

You have AutoEventWireup set to false, but there is no OnInit override for attaching an event. Try changing AutoEventWireup to true.

Change From additional information, it may be that this incorrectly identifies Firefox in the browser capabilities section of your machine.config. (or web.config).

It may also be that JavaScript is disabled in Firefox, and thus, .NET determines that it makes no sense to render Javascript material and use a different approach to postback processing if there is such a thing.

+1
source share

Based on the new information, I think itโ€™s clear that this is a Firefox problem (maybe you have a JS lock with the addition), and not a programming issue. I get great results with your code using VS 2008 and FF3 on XP Pro, as I expected, most of them will try it.

You can try reinstalling Firefox, make sure JS works on all other sites, make sure that localhost does not have different security permissions ...

+1
source share

Are you sure ASP.NET is installed on your web server?

0
source share

It seems that the __doPostBack() function is not created because it does not require server events.

ASP.NET only likes to generate the __doPostBack () function when you subscribe to event listeners that need it to work properly.

0
source share

All Articles