response.write"<script>...."
-
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
-
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
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>
-
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>
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
-
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
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
-
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
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 thescript
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> -
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 thescript
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>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
-
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
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.