Problem setting InnerText value

Discussion in 'ASP General' started by scott cooper, Mar 30, 2005.

  1. scott cooper

    scott cooper Guest

    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.
    scott cooper, Mar 30, 2005
    #1
    1. Advertising

  2. 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.



    --
    Jason Brown
    Microsoft GTSC, IIS

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

    "scott cooper" <> wrote in message
    news:u1Wv%...
    >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.
    >
    Jason Brown [MSFT], Mar 30, 2005
    #2
    1. Advertising

  3. scott cooper

    scott cooper Guest

    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.

    "Jason Brown [MSFT]" <> wrote in message
    news:...
    > 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.
    >
    >
    >
    > --
    > Jason Brown
    > Microsoft GTSC, IIS
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
    > "scott cooper" <> wrote in message
    > news:u1Wv%...
    >>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.
    >>

    >
    >
    scott cooper, Mar 30, 2005
    #3
  4. 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.


    "scott cooper" <> wrote in message
    news:...
    > 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.
    >
    > "Jason Brown [MSFT]" <> wrote in message
    > news:...
    >> 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.
    >>
    >>
    >>
    >> --
    >> Jason Brown
    >> Microsoft GTSC, IIS
    >>
    >> This posting is provided "AS IS" with no warranties, and confers no
    >> rights.
    >>
    >> "scott cooper" <> wrote in message
    >> news:u1Wv%...
    >>>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.
    >>>

    >>
    >>

    >
    >
    Jason Brown [MSFT], Mar 30, 2005
    #4
  5. scott cooper

    scott cooper Guest

    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. :)

    "Jason Brown [MSFT]" <> wrote in message
    news:...
    > 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.
    >
    >
    > "scott cooper" <> wrote in message
    > news:...
    >> 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.
    >>
    >> "Jason Brown [MSFT]" <> wrote in message
    >> news:...
    >>> 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.
    >>>
    >>>
    >>>
    >>> --
    >>> Jason Brown
    >>> Microsoft GTSC, IIS
    >>>
    >>> This posting is provided "AS IS" with no warranties, and confers no
    >>> rights.
    >>>
    >>> "scott cooper" <> wrote in message
    >>> news:u1Wv%...
    >>>>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.
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    scott cooper, Mar 30, 2005
    #5
    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. John A Grandy

    force line break inside .InnerText

    John A Grandy, Oct 17, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    6,941
    John A Grandy
    Oct 17, 2003
  2. martin

    innerText of xml doc

    martin, Mar 5, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    4,598
    martin
    Mar 6, 2004
  3. dw

    Write Panel's innerText

    dw, Sep 6, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    3,180
  4. Kerri
    Replies:
    4
    Views:
    111
    Bob Barrows
    Sep 28, 2003
  5. Srinivasa

    Problem with innerText/textContent

    Srinivasa, Feb 13, 2007, in forum: Javascript
    Replies:
    2
    Views:
    197
    Martin Honnen
    Feb 14, 2007
Loading...

Share This Page