Why was there an error?

G

Guest

Hello, friends,

A very simple code as follows, but got an error: Microsoft JScript runtime
error: 'BHnz1' is undefined.

Any ideas? Thanks a lot.

-----------------

<body MS_POSITIONING="GridLayout" onload="initCOMComponent();" >
<form id="Form1" method="post" runat="server">
<OBJECT id="BHnz1" name="BHnz1" style="Z-INDEX: 101; LEFT: 136px; TOP:
64px" classid="clsid:60EB3120-469D-5E79-839D-AB53DA2DF932"
VIEWASTEXT>
<PARAM NAME="_ExtentX" VALUE="8625">
<PARAM NAME="_ExtentY" VALUE="9155">
</OBJECT>
</form>
<script language="javascript">
function initCOMComponent()
{
BHnz1.GetBinaryDataFile("test.dat");
}
</script>
</body>
 
S

Steve C. Orr [MVP, MCSD]

It appears that the client side object BHnz1 was unable to be instantiated.
There could be many reasons depending on what BHnz1 is, but my first guesses
would be a security related issue or the component cannot be found.
 
G

Guest

we have a VB app using this component and worked fine.

and, how about security? where to find clues? thanks.
 
J

James Jardine

Andrew said:
Hello, friends,

A very simple code as follows, but got an error: Microsoft JScript runtime
error: 'BHnz1' is undefined.

Any ideas? Thanks a lot.

-----------------

<body MS_POSITIONING="GridLayout" onload="initCOMComponent();" >
<form id="Form1" method="post" runat="server">
<OBJECT id="BHnz1" name="BHnz1" style="Z-INDEX: 101; LEFT: 136px; TOP:
64px" classid="clsid:60EB3120-469D-5E79-839D-AB53DA2DF932"
VIEWASTEXT>
<PARAM NAME="_ExtentX" VALUE="8625">
<PARAM NAME="_ExtentY" VALUE="9155">
</OBJECT>
</form>
<script language="javascript">
function initCOMComponent()
{
BHnz1.GetBinaryDataFile("test.dat");
}
</script>
</body>

If you are using Visual Studio 2005 for this then check the source code
that is being generated on the client. My guess is that the id might be
getting some other text added to it. Sometimes you might see your server
side id go from BHnz1 to something like CTL001_BHNz1. If something like
this is happening then you would need to update your javascript to reference
that. Can you post the html from View... Source from the web browser.

jjardine
 
G

Guest

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Xuehanzi</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout" onload="initCOMComponent();">
<form name="Form1" method="post" action="Xhnz.aspx" id="Form1">
<input type="hidden" name="__VIEWSTATE"
value="dDwtNjU0MzcyMTk1Ozs+gVaCEI14+RbjhEr0J7c8cIwvYIk=" />

<OBJECT id="BHnz1" style="Z-INDEX: 101; LEFT: 136px; TOP: 64px"
classid="clsid:60EB3120-469D-5E79-839D-AB53DA2DF932"
name="BHnz1" VIEWASTEXT>
<PARAM NAME="_ExtentX" VALUE="8625">
<PARAM NAME="_ExtentY" VALUE="9155">
</OBJECT>
</form>
<script language="javascript">
function initCOMComponent()
{
BHnz1.GetBinaryDataFile("test.dat");
}
</script>
</body>
</HTML>
 
J

James Jardine

Andrew said:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Xuehanzi</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout" onload="initCOMComponent();">
<form name="Form1" method="post" action="Xhnz.aspx" id="Form1">
<input type="hidden" name="__VIEWSTATE"
value="dDwtNjU0MzcyMTk1Ozs+gVaCEI14+RbjhEr0J7c8cIwvYIk=" />

<OBJECT id="BHnz1" style="Z-INDEX: 101; LEFT: 136px; TOP: 64px"
classid="clsid:60EB3120-469D-5E79-839D-AB53DA2DF932"
name="BHnz1" VIEWASTEXT>
<PARAM NAME="_ExtentX" VALUE="8625">
<PARAM NAME="_ExtentY" VALUE="9155">
</OBJECT>
</form>
<script language="javascript">
function initCOMComponent()
{
BHnz1.GetBinaryDataFile("test.dat");
}
</script>
</body>
</HTML>

Does it make a difference if you try to call your method by using
Form1.GetElementById("BHnz1") instead of just BHnz1? Just an idea. Good
luck.
 
B

Bruce Barker

there are several issues hwne using com objects in the browser.

1) the object is not available for reference until form load (client side)
2) at form load the object is available, but may not actualy loaded. you
need to check readyState before accessing any properties.
3) the active/x control must be marked safe for scripting, or the browser
will not load.

try:

function initCOMComponent()
{
// test if browser allows creating of object

var o = document.getElementById("BHnz1");
if (o == null)
{
alert("this page requires you to install and trust the active/x
control 'xyz'");
return;
}

// spin until com object initialized

if (o.readyState != 4)
{
window.setTimeout("initCOMComponent()",10);
return;
}

// call methods

o.GetBinaryDataFile("test.dat");
}


-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top