JavaScript ReferenceError: Can’t find variable: __doPostBack

This error can occur in pages. In certain situations .net will fail to create the __doPostBack JavaScript function and the hidden __EVENTVALIDATION input field. The situations that can cause this are:

  • When using asp:ImageButton or asp:LinkButton controls AND:
  • When viewing the webpage using IE11
  • When viewing the webpage using an iPhone or an iPad that was updated to the latest iOS 7.

The problem revolves around the BrowserDefinitions in .NET. .NET uses these Browser Definitions to identify the capabilities of the current browser. As per default, if a browser is not known (i.e. not defined in the BrowserDefinitions), .net assumes that the browser have no JavaScript capabilities, and therefore the __doPostBack function is not needed.

Assuming that a browser is not JavaScript compatible by default in the year 2013 is probably pretty stupid. However, this is the reality and we need to cope with it. 

The browserdefintions are defined in the belly of .net (for example here: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\Browsers).

The later a .net version you have, the newer the .net version, the more likely it is that the browser is known. .NET 4.5 should know about  IE11 and the latest iPhone and iPad browsers.


There is a way to override the automatic detection of browser capabilities. Add the following to the <% Page %> directive on all of your .aspx pages:

<%@ Page Language="C#"
    Inherits="somecode" %>

Setting ClientTarget=”uplevel” forces the page to generate JavaScript as it assumes that the browser has at least the capabilities of IE6.


About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in .net, c#, General .NET and tagged , , , , . Bookmark the permalink.

One Response to JavaScript ReferenceError: Can’t find variable: __doPostBack

  1. Hi Brian

    I think i found that the problem has been fixed in .NET 4.5, and remembering than Hanselman talked about it beeing that in older versions of the .NET framework, they did browser feature detection from the Browser Definition files. This was ok, but defnetly not a good solution, as whenever a new browser is released, the Browser definition files shuold be updated.

    I think to remember thant in the newest version of the framework, they changed to feature detection, by simply asking the current browser for its features, instead of asking the browser definition files. This Means that when new browsers are released, .NET applications shuoldnt break anymore.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s