473,662 Members | 2,524 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='javas cript'>";
str += "alert('" + sb + "')";
str += "</script>";
Page.ClientScri pt.RegisterStar tupScript(this. GetType(), 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 4878
Mike P <mi*******@gmai l.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='javas cript'>";
str += "alert('" + sb + "')";
str += "</script>";
Page.ClientScri pt.RegisterStar tupScript(this. GetType(), 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.co m>
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*******@gmai l.comwrote in message
news:eG******** ******@TK2MSFTN GP05.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='javas cript'>";
str += "alert('" + sb + "')";
str += "</script>";
Page.ClientScri pt.RegisterStar tupScript(this. GetType(), 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.co mwrote:
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.co m>
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.co mwrote in message
news:MP******** *************@m snews.microsoft .com...
Leo Seccia <ls*****@msn.co mwrote:
>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.co m>
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.co mwrote:
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************ *********@msnew s.microsoft.com >, Jon Skeet
[C# MVP] <sk***@pobox.co mwrote:
Mike P <mi*******@gmai l.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='javas cript'>";
str += "alert('" + sb + "')";
str += "</script>";
Page.ClientScri pt.RegisterStar tupScript(this. GetType(), 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
2815
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) My code is below. I am getting the following error "MyForm.oNetwork.Value is Null or is not an object". I'm struggling to diagnose what to do next. I'd very much appreciate some help Many thanks <HTML><BODY><FORM NAME="MyForm"...
24
3243
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 a new window and build it with DOM rather than having to provide a src. Even a blank.html as src takes time to fetch. How can I create a popup and dynamically add DOM content without any html at all?
3
7635
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 System.Collections; .... But in all the tutorial i have seen they start with using and then
0
6427
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 be modified: if(e.CommandName =="Print") { string parsedreceipt = null; parsedreceipt = DecodeReceipt (e.Item.Cells.Text); Session = parsedreceipt;
1
2484
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 query. The showModalDailog returns a value to the original page which is used as a parameter in __doPostback, in turn trapped by the Page_Load procedure and processed.
1
1670
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 <input> control is empty) or it is. I have tryed with the following: if( filMyFile.PostedFile != null) //HtmlInputFile filMyFile; { code
6
2402
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 = "frmMySearchWebForm.aspx?DOBDate=" + txtDOBDt popUp =window.open(QueryString,null, "height=50,width=80,status=no,left =0,top =0,toolbar=no,menubar=no,location=no,scrollbars =yes"); When the user picks a certain customer in the frmMySearchWebForm I am
7
10977
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 field, it calls the JavaScript routine, which in turn calls a PHP script. The PHP script runs returns the value needed. And returns to the JavaScript. The JavaScript function is then supposed to set alerts depending on the values returned from...
0
4923
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 previous page 2. If RDP is opened in fullscreen mode, then onconnected, i want to go back to previous page.
0
8344
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8764
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7367
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5654
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4180
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1752
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.