5

********************Edit 2********************** I figured out the problem... But I don't like the implications. I was testing our iPhone targeted mobile application earlier and using a plugin to mask Firefox's User Agent String as an iPhone.

.Net was infact NOT generating the required code for post backs based on that piece of information alone.

I do not like this however, because since the iPhone and other multimedia devices can interpret javascript, ASP.net is breaking any application that relies on server generated javascript to run.

So, if the community will allow it... I'd like to change my official question to... Why will ASP.net not generate javascript for specific browsers and how can I turn this "feature" off.

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

I've got a weird problem. I copied some working code from my remote host to my computer at work. When I try to use the page I'm getting a javascript error

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

When I few the output page source, sure enough there is no server side generated javascript.

I tried creating 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've tried rebooting (hey, it works half the time), cleared out everything from App_Code, global.asax and web.config, added a textbox with autopostback=true... I'm out of ideas.

Can anyone shed some light on what's happening here?

**************More Information************** I just tried everything again in IE and it works as expected, the page source shows:

<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>

While 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 the web pages to the desktop and opening in notepad reveals the same thing...

Birk
  • 2,173
  • 4
  • 21
  • 26
  • I'm doing some research... It seems to be something you can fix with a section in web.config or machine.config. By default unknown browsers are being treated like old browser incapable of javascript. – Birk May 27 '09 at 21:02

6 Answers6

7

The problem is the default way ASP.net treats unknown browsers... such as the iPhone. Even though it would be nice to assume unknown browsers could use javascript... you can specify what capabilities that a browser has in the section of web.config or machine.config.

Check out http://slingfive.com/pages/code/browserCaps/ for an updated browsercaps config file for asp.net

Here is an example of a case to match 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>
Birk
  • 2,173
  • 4
  • 21
  • 26
  • You beat me to it - BrowserCaps are indeed the issue here - You might want to check out http://owenbrady.net/browsercaps/ it's more recently updated for both 1.1 and 2.0 - props to http://stackoverflow.com/questions/431765/asp-net-request-browser-crawler-dynamic-crawler-list/431991#431991 for this one. – Zhaph - Ben Duguid May 28 '09 at 20:17
2

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

Gromer
  • 9,861
  • 4
  • 34
  • 55
  • I figured out the problem (and edited the question) It was a user-agent spoofing plugin I've been using for testing. Although I'm not happy at all that that was the issue. – Birk May 27 '09 at 20:44
  • At least you found the answer! – Gromer May 27 '09 at 20:48
1

You have AutoEventWireup set to false, but no Override of OnInit to attach the event. Try changing the AutoEventWireup to true.

Edit: From the more information it could be that it is incorrectly identifying Firefox in the brower capabilities section of your machine.config. (or web.config).

It could also be that JavaScript is turned off in Firefox, and thus .NET is determining that there is no point rendering the Javascript stuff, and should use a different approach to postback handling, if there is such a thing.

David McEwing
  • 3,320
  • 18
  • 16
1

Based on the new information, I think it's clear that this is a Firefox problem (perhaps you have an add-on blocking JS), and not a programming question. I get fine results with your code using VS 2008 and FF3 on XP Pro, as I'd expect will most anyone else trying it.

You may try reinstalling Firefox, ensure that JS works on all other sites, make sure localhost doesn't have different security permissions...

CarmineSantini
  • 294
  • 3
  • 6
0

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

Chris
  • 2,959
  • 1
  • 30
  • 46
0

It looks like the __doPostBack() function is not being generated because you have no server-side events which require it.

ASP.NET likes to only generate the __doPostBack() function when you have event listeners subscribed that would need it to function correctly.

Dan Herbert
  • 99,428
  • 48
  • 189
  • 219
  • Protected Sub linkTest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles linkTest.Click There's my event handler... and like I said, when it was on my home computer, and my web server it was working correctly. – Birk May 27 '09 at 19:57
  • Whoops, I overlooked the fact that you were using a LinkButton. I was thinking that was a Button control, which doesn't need the __doPostBack() method, if I recall correctly. Also, because AutoEventWireup is false, it doesn't look like that method would be tied to the control by itself, but someone else already mentioned that... – Dan Herbert May 27 '09 at 20:19