F
Frank
Hi,
I am working with VS.NET 2005
Ultimately, I wish to call a JavaScript function from a .js file
In the Master page, I have:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Admin Pages</title>
<link href="common/css/admin_style.css" rel="stylesheet" type="text/css"
/>
<script language="JavaScript" src="common/js/global.js"
type="text/JavaScript"></script>
</head>
<body runat="server" id="body">
.
.
.
</body>
</html>
In the individual page code behind where I wish to call the js function, it
works if I use:
protected void Page_Load(object sender, EventArgs e)
{
try
{
string temp = "alert('Hello World!');";
HtmlGenericControl body =
(HtmlGenericControl)Master.FindControl("Body");
body.Attributes.Add("onload", temp);
}
catch (NullReferenceException x)
{
Response.Write(x);
}
}
But if I try to call a function from the js file like so:
protected void Page_Load(object sender, EventArgs e)
{
try
{
string temp = "TestJS();";
HtmlGenericControl body =
(HtmlGenericControl)Master.FindControl("Body");
body.Attributes.Add("onload", temp);
}
catch (NullReferenceException x)
{
Response.Write(x);
}
}
It fails. I don't get an ASP.NET exception, but rather a JavaScript error
which states it is expecting an object, but I can't figure out what object
it means. My js file looks like this:
// JScript File
function TestJS()
{
alert('Hello World!'};
}
The rendered html contains :
<body id="ctl00_body" onload="TestJS();">
Can anyone give some help please?
Frustrated to no end over what should be a simple operation!!
I am working with VS.NET 2005
Ultimately, I wish to call a JavaScript function from a .js file
In the Master page, I have:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Admin Pages</title>
<link href="common/css/admin_style.css" rel="stylesheet" type="text/css"
/>
<script language="JavaScript" src="common/js/global.js"
type="text/JavaScript"></script>
</head>
<body runat="server" id="body">
.
.
.
</body>
</html>
In the individual page code behind where I wish to call the js function, it
works if I use:
protected void Page_Load(object sender, EventArgs e)
{
try
{
string temp = "alert('Hello World!');";
HtmlGenericControl body =
(HtmlGenericControl)Master.FindControl("Body");
body.Attributes.Add("onload", temp);
}
catch (NullReferenceException x)
{
Response.Write(x);
}
}
But if I try to call a function from the js file like so:
protected void Page_Load(object sender, EventArgs e)
{
try
{
string temp = "TestJS();";
HtmlGenericControl body =
(HtmlGenericControl)Master.FindControl("Body");
body.Attributes.Add("onload", temp);
}
catch (NullReferenceException x)
{
Response.Write(x);
}
}
It fails. I don't get an ASP.NET exception, but rather a JavaScript error
which states it is expecting an object, but I can't figure out what object
it means. My js file looks like this:
// JScript File
function TestJS()
{
alert('Hello World!'};
}
The rendered html contains :
<body id="ctl00_body" onload="TestJS();">
Can anyone give some help please?
Frustrated to no end over what should be a simple operation!!