brotherbill999
asked on
ASP.NET VB.NET Why is control undefined?
When screen is displayed using ASP.NET, IE6 provides error message:
Line 14
Char 9
Error: 'CheckBox1' is undefined
Code: 0
URL: http://localhost/atlins2/controls/toy.aspx
VB.NET source Code
-----------------------
<%@ Page Language="VB" %>
<!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>Untitled Page</title>
<script language="javascript">
CheckBox1.onClick = CheckBox1_Changed;
function CheckBox1_Changed() {
alert("CheckBox1 Changed")
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:CheckBox ID="CheckBox1" runat="server" Text="CheckBox1" />
</form>
</body>
</html>
Code as seen by Internet Explorer 6
-------------------------- ---------- --------
<!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><title>
Untitled Page
</title>
<script language='javascript' src='http://127.0.0.1:1026/js.cgi?caw&r=16944'></script>
<script language="javascript">
CheckBox1.onClick = CheckBox1_Changed; /* Tried this */
function window.onload() { /* and tried this too */
CheckBox1.onClick = CheckBox1_Changed;
}
function CheckBox1_Changed() {
alert("CheckBox1 Changed")
}
</script>
</head>
<body>
<form name="form1" method="post" action="toy.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE3MzUzNTI zMDhkGAEFH l9fQ29udHJ vbHNSZXF1a XJlUG9zdEJ hY2tLZXlfX xYBBQlDaGV ja0JveDGuI pQWwMDERj7 uUtS6dBud+ lEwrw==" />
</div>
<input id="CheckBox1" type="checkbox" name="CheckBox1" /><label for="CheckBox1">CheckBox1< /label>
<div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgLZg5nTBAKC5Ne 7CUdNgqqnp nm1Xeak0Aq o72nkX74K" />
</div></form>
</body>
</html>
--------------------------
What needs to change so that the event callback for checkbox can work?
Line 14
Char 9
Error: 'CheckBox1' is undefined
Code: 0
URL: http://localhost/atlins2/controls/toy.aspx
VB.NET source Code
-----------------------
<%@ Page Language="VB" %>
<!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>Untitled Page</title>
<script language="javascript">
CheckBox1.onClick = CheckBox1_Changed;
function CheckBox1_Changed() {
alert("CheckBox1 Changed")
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:CheckBox ID="CheckBox1" runat="server" Text="CheckBox1" />
</form>
</body>
</html>
Code as seen by Internet Explorer 6
--------------------------
<!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><title>
Untitled Page
</title>
<script language='javascript' src='http://127.0.0.1:1026/js.cgi?caw&r=16944'></script>
<script language="javascript">
CheckBox1.onClick = CheckBox1_Changed; /* Tried this */
function window.onload() { /* and tried this too */
CheckBox1.onClick = CheckBox1_Changed;
}
function CheckBox1_Changed() {
alert("CheckBox1 Changed")
}
</script>
</head>
<body>
<form name="form1" method="post" action="toy.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE3MzUzNTI
</div>
<input id="CheckBox1" type="checkbox" name="CheckBox1" /><label for="CheckBox1">CheckBox1<
<div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgLZg5nTBAKC5Ne
</div></form>
</body>
</html>
--------------------------
What needs to change so that the event callback for checkbox can work?
ASKER
Hi gops1,
Tried that, but it didn't work. Keep trying. Better yet, build a toy, get it working, and then you'll *know* you have a solution.
Brother Bill
<%@ Page Language="VB" %>
<!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>Untitled Page</title>
<script language="javascript">
function window.onload() {
document.form1.CheckBox1.o nClick = CheckBox1_Changed; /* Changed it according to your tip. Didn't help */
}
function CheckBox1_Changed() {
alert("CheckBox1 Changed")
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:CheckBox ID="CheckBox1" runat="server" Text="CheckBox1" />
</form>
</body>
</html>
Tried that, but it didn't work. Keep trying. Better yet, build a toy, get it working, and then you'll *know* you have a solution.
Brother Bill
<%@ Page Language="VB" %>
<!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>Untitled Page</title>
<script language="javascript">
function window.onload() {
document.form1.CheckBox1.o
}
function CheckBox1_Changed() {
alert("CheckBox1 Changed")
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:CheckBox ID="CheckBox1" runat="server" Text="CheckBox1" />
</form>
</body>
</html>
ASKER
Here is what does work.
1. add onload function with parenthesis to <body onload= ... >
2. for convenience, define a variable for CheckBox1 = document.form1.CheckBox1
3. when using onclick event, use all lowercase.
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="javascript">
var CheckBox1;
function load() {
alert("load");
CheckBox1 = document.form1.CheckBox1
CheckBox1.onclick = CheckBox1_Changed;
}
function CheckBox1_Changed() {
alert("CheckBox1 Changed")
}
</script>
</head>
<body onload=load()>
<form id="form1" runat="server">
<asp:CheckBox ID="CheckBox1" runat="server" Text="CheckBox1" />
</form>
</body>
</html>
1. add onload function with parenthesis to <body onload= ... >
2. for convenience, define a variable for CheckBox1 = document.form1.CheckBox1
3. when using onclick event, use all lowercase.
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="javascript">
var CheckBox1;
function load() {
alert("load");
CheckBox1 = document.form1.CheckBox1
CheckBox1.onclick = CheckBox1_Changed;
}
function CheckBox1_Changed() {
alert("CheckBox1 Changed")
}
</script>
</head>
<body onload=load()>
<form id="form1" runat="server">
<asp:CheckBox ID="CheckBox1" runat="server" Text="CheckBox1" />
</form>
</body>
</html>
ASKER
This post may be closed...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
May be it should be like this:
document.form1.CheckBox1.o