********************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 is breaking any application that relies on server generated javascript to run.
So, if the munity will allow it... I'd like to change my official question to... Why will ASP 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 puter 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" ".dtd">
<html xmlns="">
<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...
********************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 is breaking any application that relies on server generated javascript to run.
So, if the munity will allow it... I'd like to change my official question to... Why will ASP 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 puter 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/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3/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...
Share Improve this question edited May 27, 2009 at 20:42 Birk asked May 27, 2009 at 19:50 BirkBirk 2,1834 gold badges21 silver badges26 bronze badges 1- I'm doing some research... It seems to be something you can fix with a <browserCaps> section in web.config or machine.config. By default unknown browsers are being treated like old browser incapable of javascript. – Birk Commented May 27, 2009 at 21:02
6 Answers
Reset to default 7The problem is the default way ASP 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./pages/code/browserCaps/ for an updated browsercaps config file for asp
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>
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?
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...
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.
Are you sure you have ASP.NET installed on your web server?
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.