How to create a Server Object in a Function?

Discussion in 'ASP General' started by thisis, Nov 4, 2006.

  1. thisis

    thisis Guest

    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?
     
    thisis, Nov 4, 2006
    #1
    1. Advertising

  2. thisis

    Mike Brind Guest

    "thisis" <> wrote in message
    news:...
    > 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/

    --
    Mike Brind
     
    Mike Brind, Nov 4, 2006
    #2
    1. Advertising

  3. "Mike Brind" <> wrote in message
    news:Oc$...
    >
    > "thisis" <> wrote in message
    > news:...
    > > 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.
     
    Anthony Jones, Nov 5, 2006
    #3
  4. thisis

    Mike Brind Guest

    "Anthony Jones" <> wrote in message
    news:...
    >
    > "Mike Brind" <> wrote in message
    > news:Oc$...
    >>
    >> "thisis" <> wrote in message
    >> news:...
    >> > 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?
     
    Mike Brind, Nov 5, 2006
    #4
  5. thisis

    thisis Guest

    Mike Brind wrote:
    > "Anthony Jones" <> wrote in message
    > news:...
    > >
    > > "Mike Brind" <> wrote in message
    > > news:Oc$...
    > >>
    > >> "thisis" <> wrote in message
    > >> news:...
    > >> > 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?
     
    thisis, Nov 6, 2006
    #5
  6. thisis

    Mike Brind Guest

    "thisis" <> wrote in message
    news:...
    >
    > Mike Brind wrote:
    >> "Anthony Jones" <> wrote in message
    >> news:...
    >> >
    >> > "Mike Brind" <> wrote in message
    >> > news:Oc$...
    >> >>
    >> >> "thisis" <> wrote in message
    >> >> news:...
    >> >> > 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
     
    Mike Brind, Nov 6, 2006
    #6
  7. Mike Brind wrote:
    > >
    > > Why does it need to asynchronous? I many cases this is undesirable.
    > >

    >
    > How do you mean?


    In most cases further processing of subsequent code would be nonsense until
    the result of the function has returned. It also leaves the UI live and
    accepting other user events, handling these correctly whilst an outstanding
    operation is in effect can be tricky.

    I was wondering why this case would warrant it? It's difficult to see what
    Thisis intends since the code appears to be doing some very strange things
    to start with e.g.:-

    Body_Onload = obj.cTestDelete
     
    Anthony Jones, Nov 6, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Vanns
    Replies:
    7
    Views:
    7,047
    Evan Carew
    Jan 21, 2004
  2. Petri Savolainen
    Replies:
    0
    Views:
    443
    Petri Savolainen
    Jul 1, 2003
  3. jon wayne
    Replies:
    9
    Views:
    712
    Jim Langston
    Sep 22, 2005
  4. Paul Childs
    Replies:
    1
    Views:
    321
    Matimus
    Jun 3, 2008
  5. alex
    Replies:
    3
    Views:
    532
    Richard Cornford
    Dec 28, 2006
Loading...

Share This Page