Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. response.write"<script>...."

response.write"<script>...."

Scheduled Pinned Locked Moved ASP.NET
helpjavatools
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eshban284
    wrote on last edited by
    #1

    I am having a problem in small file where the ASP code contains java scripting where we r opening a new window but it is not working the error says invalid property assignment 'response.write' EsHbAn BaHaDuR

    A 1 Reply Last reply
    0
    • E eshban284

      I am having a problem in small file where the ASP code contains java scripting where we r opening a new window but it is not working the error says invalid property assignment 'response.write' EsHbAn BaHaDuR

      A Offline
      A Offline
      Alsvha
      wrote on last edited by
      #2

      What does the code look like? Your response.write? A simple Response.Write(" Insert JavaScript Here ") should suffice I would think. --------------------------- 127.0.0.1 - Sweet 127.0.0.1

      N 1 Reply Last reply
      0
      • A Alsvha

        What does the code look like? Your response.write? A simple Response.Write(" Insert JavaScript Here ") should suffice I would think. --------------------------- 127.0.0.1 - Sweet 127.0.0.1

        N Offline
        N Offline
        NeverHeardOfMe
        wrote on last edited by
        #3

        It's odd, but I've seen dozens of examples with code such as yours above, and I always get a fatal error when I try - the only way I get it to work is by splitting the string at the closing script tag, thus: string = " Insert JavaScript Here <" + "/script>" Explain that?! But it works... cheers Phil </x-turndown>

        A 1 Reply Last reply
        0
        • N NeverHeardOfMe

          It's odd, but I've seen dozens of examples with code such as yours above, and I always get a fatal error when I try - the only way I get it to work is by splitting the string at the closing script tag, thus: string = " Insert JavaScript Here <" + "/script>" Explain that?! But it works... cheers Phil </x-turndown>

          A Offline
          A Offline
          Alsvha
          wrote on last edited by
          #4

          My guess would be that the string isn't terminated proberly. Also depending on what code is used it could be you need to escape some of the ". For instance if you use " in both the string and javascript, you need to esacpe the "'s in the javascript (which is why I personal belive it is better to use ' for strings in javascript making it easier to differ between javascript strings and asp.net strings). For instance: Response.Write("alert("Hello World")") where Hello World is actually outside the string, and thus it would fail. But untill I (we) see an exampel of the code which fails, it is hard to say what is excatly wrong with it :) edit: forgot closing the script tag :o --------------------------- 127.0.0.1 - Sweet 127.0.0.1

          N 1 Reply Last reply
          0
          • A Alsvha

            My guess would be that the string isn't terminated proberly. Also depending on what code is used it could be you need to escape some of the ". For instance if you use " in both the string and javascript, you need to esacpe the "'s in the javascript (which is why I personal belive it is better to use ' for strings in javascript making it easier to differ between javascript strings and asp.net strings). For instance: Response.Write("alert("Hello World")") where Hello World is actually outside the string, and thus it would fail. But untill I (we) see an exampel of the code which fails, it is hard to say what is excatly wrong with it :) edit: forgot closing the script tag :o --------------------------- 127.0.0.1 - Sweet 127.0.0.1

            N Offline
            N Offline
            NeverHeardOfMe
            wrote on last edited by
            #5

            wierder and wierder... I would love to post an example, but even here it goes funny - it's the final closing script tag, again... I copy my code in here, and when I hit "Preview", the line with that tag on it is truncated at that tag! This (must be) what happnes in my VS too, as it's a compilation error (string must end with double quotes) - but it is!! I am a programmer with many years experience by now, I'm not usually caught out by something as daft as this... there are no quotes inside quotes (as per your example - nothing so obvious. If you are interested enough, I have posted the code here: http://www.psu.me.uk/javascript.html[^] this is just a simple example I made up to show what is going on.... thanks Phil

            M 1 Reply Last reply
            0
            • N NeverHeardOfMe

              wierder and wierder... I would love to post an example, but even here it goes funny - it's the final closing script tag, again... I copy my code in here, and when I hit "Preview", the line with that tag on it is truncated at that tag! This (must be) what happnes in my VS too, as it's a compilation error (string must end with double quotes) - but it is!! I am a programmer with many years experience by now, I'm not usually caught out by something as daft as this... there are no quotes inside quotes (as per your example - nothing so obvious. If you are interested enough, I have posted the code here: http://www.psu.me.uk/javascript.html[^] this is just a simple example I made up to show what is going on.... thanks Phil

              M Offline
              M Offline
              minhpc_bk
              wrote on last edited by
              #6

              Hi Phil, As you may already know that when the user makes request for a web page for the first time, a new class is generated and compiled to an assembly. The source code of this class is the result of parsing the .aspx content files. Here, you want to define the server code inline, so you basically need to put it between the open and close tags of the script element. If you happen to use a string contant in the inline server code, this contant should not contain the close tag of the script element, otherwise the source code of the dynamic class is not generated properly. It will look something like:

              Line ...: Sub Page_Load(Sender As Object, e As EventArgs)
              Line ...: Dim strScript As String = "document.forms(0).tbRight.value = "
              Line ...: strScript += "document.forms(0).tbLeft.value;</pre>and of couse it will cause a compile error saying <code>"String constants must end with a double quote"</code> at runtime. So to work around this error, you need to split the close <code>script</code> tag in the string contant. For more information on the dynamically generated class, you can simply click on the links on the web page:

              <code>Show Detailed Compiler Output
              Show Complete Compilation Source</code> </x-turndown>

              N 1 Reply Last reply
              0
              • M minhpc_bk

                Hi Phil, As you may already know that when the user makes request for a web page for the first time, a new class is generated and compiled to an assembly. The source code of this class is the result of parsing the .aspx content files. Here, you want to define the server code inline, so you basically need to put it between the open and close tags of the script element. If you happen to use a string contant in the inline server code, this contant should not contain the close tag of the script element, otherwise the source code of the dynamic class is not generated properly. It will look something like:

                Line ...: Sub Page_Load(Sender As Object, e As EventArgs)
                Line ...: Dim strScript As String = "document.forms(0).tbRight.value = "
                Line ...: strScript += "document.forms(0).tbLeft.value;</pre>and of couse it will cause a compile error saying <code>"String constants must end with a double quote"</code> at runtime. So to work around this error, you need to split the close <code>script</code> tag in the string contant. For more information on the dynamically generated class, you can simply click on the links on the web page:

                <code>Show Detailed Compiler Output
                Show Complete Compilation Source</code> </x-turndown>

                N Offline
                N Offline
                NeverHeardOfMe
                wrote on last edited by
                #7

                OK, thanks, minhpc_bk, that makes sense... but what confuses me is that I have seen lots of examples posted along the lines of my code, and never seen this problem mentioned - surely the posters of such snippets would have experienced the same, and put in the split script tag? Oh well, as long we have something that works... thanks Phil

                M 1 Reply Last reply
                0
                • N NeverHeardOfMe

                  OK, thanks, minhpc_bk, that makes sense... but what confuses me is that I have seen lots of examples posted along the lines of my code, and never seen this problem mentioned - surely the posters of such snippets would have experienced the same, and put in the split script tag? Oh well, as long we have something that works... thanks Phil

                  M Offline
                  M Offline
                  minhpc_bk
                  wrote on last edited by
                  #8

                  In fact, this error only occurs when we put the code inline. If we use code-behind, this error does not happen. So IMHO, the posters might have thought that the readers also use the code-behind model by default in order to run the sample code in the same way as they did.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups