Problem setting InnerText value

S

scott cooper

I hope this illustrates my question a little better. Consider the following
script; why does the client side script change the div object's innerHtml
property but the server side script does not? Debug reports that the server
script does not see the document's div object but I thought I read that
varibles created with page scope are available throughout the page.


<%@ language="VBSCRIPT" %>
<html>
<head>
<script language="vbscript">
Sub chgDivText
oDiv1.InnerHtml="Div changed by button"
End sub
</script>
</head>
<body>
<div id="oDiv1">Div Label</div>
<button onclick="chgdivtext">"Change Div Text"</button>
</body>
<%
oDiv1.InnerHtml="Div changed by server"
%>
</html>

Thanks for your help.
 
J

Jason Brown [MSFT]

What you read was correct, but what you're missing is that the script there
runs at two different times. The server-side script runs before the page is
ever delivered to the browser, so doesn't have access to client-side data.
An ASP variable is accessible throughout the page, but any client-side
objects or variables (such as DOM references) are most definitely not
available.
 
S

scott cooper

Thanks, I kind of thought that was the case but I dont understand why an
object I created in the server script could not be used by a client side
script and returned the object required error when I tried read one of the
object's properties.
 
J

Jason Brown [MSFT]

in ASP, client and server are two separate environments and should be
treated as such. ASP.NET tries to blur the boundary somewhat, with
server-side objects and events which can either smotth things or complicate
things depending on your level of understanding.


--
Jason Brown
Microsoft GTSC, IIS

This posting is provided "AS IS" with no warranties, and confers no
rights.
 
S

scott cooper

Thank you Jason. It seemed to me that I should be able to referance
variables and objects created by a server script but your words make sense
to me. I guess it might have been wishful coding. :)
 

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

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top