Accessing page variables in embedded javascript

  • Thread starter Thread starter cowznofsky
  • Start date Start date
C

cowznofsky

I am migrating an app from VS2003 to VS2005

There are some public variables in the page behind code that are
referenced in javascript blocks at various places in the html. But
they're not working anymore.

For example, we have an activex control, and we want to use it's id
within script

In the page behind code:

Public ReadOnly Property MyActiveXId() As String
Get
Return '" MyActiveX.ClientID "
End Get
End Property

and in the javacript:

var oViewer = document.forms[0][<%=MyActiveXid%>];

This code evidently used to work, but now causes the error "Object
Reference not set to an object".
(Also mind-numbing is that the error occurs on this line even when
I've commented it out.)
 
I am migrating an app from VS2003 to VS2005
There are some public variables in the code behind page that are
referenced in JavaScript blocks at various places in the HTML.  But
they're not working anymore.
For example, we have an ActiveX control, and we want to use its ID
within script
In the page behind code:
  Public ReadOnly Property MyActiveXId() As String
        Get
           Return '"  MyActiveX.ClientID  "
       End Get
   End Property
and in the JavaScript:
var oViewer = document.forms[0][<%=MyActiveXid%>];
This code evidently used to work, but now causes the error "Object
Reference not set to an object".
(Also mind-numbing is that the error occurs on this line even when
I've commented  it out.)

It's not actually necessary to use an explicit property for this...

Does this work:?
var oViewer = document.getElementById('<%=MyActiveX.ClientID%>');

Also, make sure you aren't using the language property in the <script />
tag...

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net- Hide quoted text -

- Show quoted text -

Ok, I can try that.

But on your second point, yes, I was using the language property.
The original code looked like this:
<SCRIPT lang="javascript">
and I've changed to this while trying to make it work:
<SCRIPT type="text/javascript" language="javascript">

And I should change that?
 
is it a server error or javascript error?

if you put a runat="server" on an object tag then the active/x control
is created on the server not the client.

-- bruce (sqlwork.com)
 
Back
Top