I had developed a ASP.NET
application using .NET 3.5 framework
and deployed in the IIS
in application pool DefaultAppPool
.
Code:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Test.aspx.vb" Inherits="Sample.sample"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Test</title>
<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body onload="document.frmTest.btnAdd.focus();">
<form id="frmTest" method="post" runat="server">
<input tabIndex="9" type="button" value="Add" name="btnAdd">
</form>
</body>
</HTML>
It is running without any issues for past 2 years.
Now, I have changed the application pool from DefaultAppPool
to ASP.NET v4.0 Integrated Pipeline
mode in IIS
.
The application throws the error
SCRIPT5007: Unable to get property 'btnAdd' of undefined or null reference
Note: I have revert the application pool to DefaultAppPool
, the application runs without any error.
What is the cause for this error? Is there any setting to be changed to fix the error?
Change your code to instead use
document.forms['frmTest'].btnAdd.focus();
Or specify name attribute to the form element as below:
<form method="post" action="Default" name="frmTest">
When you are changing the framework version, .net is probably adding additional attributes to the aspx page and hence the code seems to work with the default app pool .net framework 2.0
Update:
The reason is, In ASP.NET v4.0
the name
attribute for form
tag is not generated while rendering the page.
We can fix this by addding below setting in the <system.web>
tag in the application's web.config
file
<pages controlRenderingCompatibilityVersion="3.5" />