"thisis" <he******@web.dewrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>
Mike Brind wrote:
>"Anthony Jones" <An*@yadayadayada.comwrote in message
news:ek**************@TK2MSFTNGP03.phx.gbl...
>
"Mike Brind" <pa*******@hotmail.comwrote in message
news:Oc**************@TK2MSFTNGP02.phx.gbl...
"thisis" <he******@web.dewrote in message
news:11**********************@m73g2000cwd.googleg roups.com...
Hi All,
i have this.asp page:
<script type="text/vbscript">
Function Body_Onload()
' create the object
Set obj = Server.CreateObject("UploadImage.cTest")
' use method of the object
Body_Onload = obj.cTestDelete
Set obj = Nothing
End Function
</script>
<html>
<body onload="Body_Onload()">
</body>
</html>
the this.asp gives an Error while running:
Line 4
Char 1
Error Object required 'Server'
Code 0
URL http://127.0.0.1/this/this.asp
my Question:
How to create a Server Object in a Function?
You can't call server-side code directly from client-side code.
You'll
need
to send an asynchronous http request from the browser to a server-side
script which can then make calls to Server.CreateObject. Some people
call
it Ajax. Have a look here: http://www.w3schools.com/ajax/
Why does it need to asynchronous? I many cases this is undesirable.
How do you mean?
Hi Mike Brind,
I looked at the link you gave, thanks.
I don't understand what's ajax got to do with my question in the start
of this thread:
How to create a Server Object in a Function using VBScript?
Read the first line of my first response again: you can't call server-side
code directly from client-side code.
Your error occurs when you make a call in your function to
Server.CreateObject. Note: the big hint here is SERVER.CreateObject. ASP
code runs on the web server that the site is housed on, so you can only put
Server.CreateObject in ASP code. You can't put it in client side VBScript -
your Body_Onload() function, which runs on the user's browser - not the web
server.
The client side VBScript will only run after the page has finished executing
on the server and the response has been sent to the client. As far as the
web server is concerned, the page has finished and doesn't exist anymore.
Therefore, if you want to make use of server-side functionality once the
page has been assembled in the user's browser, you need to either get the
user to post the entire page back and respond to that event, or make use of
some event on the page to do a kind of partial post-back where the page
stays in the user's browser. This is where ajax comes in.
However, it seems to me pointless to make a call to server-side script when
the html body is still loading in the user's browser. Maybe someone else
will provide some obscure examples of when this is the right thing to do,
but at that point, there is no chance for user interaction, so you should
really move your Server.CreateObject to your ASP code in my view.
--
Mike Brind