473,508 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using stringbuilder with javascript alert

I am trying to build up some text in a stringbuilder and then use
javascript to show it with an alert box.

Here is my attempt to show it in an alert box :
string str = "";
str += "<script language='javascript'>";
str += "alert('" + sb + "')";
str += "</script>";
Page.ClientScript.RegisterStartupScript(this.GetTy pe(), key,
str);

This works fine until I start trying to add /n's to my stringbuilder to
force new lines. When I do this I get the error 'unterminated string
constant'.

Can anybody help?

*** Sent via Developersdex http://www.developersdex.com ***
Jul 11 '08 #1
6 4858
Mike P <mi*******@gmail.comwrote:
I am trying to build up some text in a stringbuilder and then use
javascript to show it with an alert box.

Here is my attempt to show it in an alert box :
string str = "";
str += "<script language='javascript'>";
str += "alert('" + sb + "')";
str += "</script>";
Page.ClientScript.RegisterStartupScript(this.GetTy pe(), key,
str);

This works fine until I start trying to add /n's to my stringbuilder to
force new lines. When I do this I get the error 'unterminated string
constant'.

Can anybody help?
Well for a start, that's not using StringBuilder at all.

To get a string with the contents "\n" you need to escape the
backslash, so you end up with "\\n" in your source code.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
Jul 11 '08 #2
In stringbuilder try to add new lines as as '//n'...

Leo

"Mike P" <mi*******@gmail.comwrote in message
news:eG**************@TK2MSFTNGP05.phx.gbl...
>I am trying to build up some text in a stringbuilder and then use
javascript to show it with an alert box.

Here is my attempt to show it in an alert box :
string str = "";
str += "<script language='javascript'>";
str += "alert('" + sb + "')";
str += "</script>";
Page.ClientScript.RegisterStartupScript(this.GetTy pe(), key,
str);

This works fine until I start trying to add /n's to my stringbuilder to
force new lines. When I do this I get the error 'unterminated string
constant'.

Can anybody help?

*** Sent via Developersdex http://www.developersdex.com ***
Jul 11 '08 #3
Leo Seccia <ls*****@msn.comwrote:
In stringbuilder try to add new lines as as '//n'...
Careful with the slash direction - it should be "\\n" instead of "//n".

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
Jul 11 '08 #4
lol, the initial description of the problem tricked me (it said /n)... and
as you sat that isn't stringbuilder at all, he is just concatenating a
string.
O well, good old Friday.
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
Leo Seccia <ls*****@msn.comwrote:
>In stringbuilder try to add new lines as as '//n'...

Careful with the slash direction - it should be "\\n" instead of "//n".

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
Jul 11 '08 #5
On Fri, 11 Jul 2008 02:55:57 -0700, Leo Seccia <ls*****@msn.comwrote:
lol, the initial description of the problem tricked me (it said /n)...
and as you sat that isn't stringbuilder at all, he is just concatenating
a string.
Well, maybe. It could just be a poorly-stated question. He does have a
variable named "sb" that he fails to show how it's initialized or used.
Maybe that's the StringBuilder instance to which he's referring. :)
Jul 11 '08 #6
In article <MP*********************@msnews.microsoft.com>, Jon Skeet
[C# MVP] <sk***@pobox.comwrote:
Mike P <mi*******@gmail.comwrote:
I am trying to build up some text in a stringbuilder and then use
javascript to show it with an alert box.

Here is my attempt to show it in an alert box :
string str = "";
str += "<script language='javascript'>";
str += "alert('" + sb + "')";
str += "</script>";
Page.ClientScript.RegisterStartupScript(this.GetTy pe(), key,
str);

This works fine until I start trying to add /n's to my stringbuilder to
force new lines. When I do this I get the error 'unterminated string
constant'.

Can anybody help?

Well for a start, that's not using StringBuilder at all.

To get a string with the contents "\n" you need to escape the
backslash, so you end up with "\\n" in your source code.
Or (if he had been using a string builder) sb.AppendLine("value")....

--
J.B. Moreno
Jul 12 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2809
by: NewbieJon | last post by:
I am attempting to send the variable "sComputerName" from my ActiveX script to "GetInfo.asp" using javascript. (Having been advised this is the way to get my ActiveX variable into my ASP script) ...
24
3213
by: jonathon | last post by:
Hi all, I have a web app with a popup window for entering data. I don't want to access the web every time this window is opened, as most of the app is AJAX. But I can't figure out how to open...
3
7628
by: Digital Fart | last post by:
I was looking at the GFAX - Gnome fax application and i see that in the main.cs the author puts the using inside his namespace. namespace gfax { using System; using System.IO; using...
0
6414
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to...
1
2476
by: Adrian | last post by:
I appear to be losing ViewState information when calling the __doPostBack function. I am attempting to use the showModalDialog to load a new web page which confirms that a user wishes to save a...
1
1664
by: Viktor Popov | last post by:
Hi, I'm trying to upload a file and I do that with this code, but there is a thing which doesn't work. I can't understand how to check if it isn't written the path to the file(the text field of...
6
2389
by: Shashi | last post by:
I have developed ASP.Net application using .Net 1.1 Framework. When the user clicks image file through Java script I am using my search window as below. QueryString =...
7
10967
by: C.Joseph Drayton | last post by:
I have a problem that I am hoping someone can help me with. First let me describe the problem. I have an HTML form that in one field has an onBlur call to a JavaScript function. When you exit the...
0
4902
AnuSumesh
by: AnuSumesh | last post by:
Hi All, I want to call RDP on Page load and it is working fine.My code is in C#. But I am unable to perform following functions 1. when i disconnected from RDP, i want to go back to...
0
7226
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7125
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7499
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5631
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3199
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.