MajorGeeks Support Forums

Go Back   MajorGeeks Support Forums > ----------= PC, Desktop and Laptop Support =---------- > Software
Register FAQ Members List Calendar Casino Mark Forums Read

Software Software such as operating systems like Windows XP, Windows Vista, Windows 7 etc., or specific programs.


Reply
 
Thread Tools Display Modes
  #1  
Old 08-17-07, 13:18
MBlock MBlock is offline
Private First Class
 
Join Date: Mar 2005
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default Javascript in C#.Net web application

Hey everyone,

I have what I imagine is a pretty basic question but I am just getting into javascript. I want to create a new line break in a javascript message for my web app I am working on. Right now the dialog box pop up is too long and I want to just have two lines of text instead of all on one. The code I have is:

string sJavaScript ="";
sJavaScript = "<script language='javascript'>";
sJavaScript += "alert('Line1 '\n' Line2');";
sJavaScript += "</scr" + "ipt>";
Response.Write(sJavaScript);

When I run that IE gives me a javascript error saying:

Line: 2
Char: 1
Error: Expected ')'
Code: 0

And no pop-up is displayed. if I remove the '\n' part than it displays just fine... but all on one line. if I remove the two apostrophe's and just have the \n in between the lines than I get an error that says "Unterminated string constant" and Line: 1 and Char: 78


Please ANY insight or advice as soon as possible would be greatly appreciated! TIA!
Reply With Quote
Sponsored links
  #2  
Old 08-20-07, 11:32
MBlock MBlock is offline
Private First Class
 
Join Date: Mar 2005
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: Javascript in C#.Net web application

Problem solved. Just in case anyone else ever comes across this problem. The solution is as follows:

Since I was using Visual Studios and adding all the J Script to a string variable THEN passing the string into it's runtime what I had written was " Line 1 \n Line 2" this was merely creating a new line in the runtime and not being processed as a new line in the alert box so the escape sequence of \n was not actually getting written into the runtime. So I simply needed to dereference the '\n' operation by using the following sintax

alert('Line 1 \\n Line 2')

That way the \n was getting carried through the string creation and being passed into the runtime.
Reply With Quote
  #3  
Old 08-23-07, 13:41
Kodo's Avatar
Kodo Kodo is offline
SNATCHSQUATCH
 
Join Date: Jan 2002
Location: Syracuse NY, USA
Posts: 11,502
Thanks: 17
Thanked 72 Times in 49 Posts
Default Re: Javascript in C#.Net web application

string sJavaScript ="";
sJavaScript = @"alert('Line1 \n\r Line2');";
ClientScript.RegisterScriptBlock(this.GetType(),"__test",sJavaScript,true);
__________________
"The American people will never knowingly adopt Socialism..." -Norman Thomas

Last edited by Kodo; 08-25-07 at 16:00..
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript yoduh Software 1 06-02-07 15:19
Javascript help Computer Acolyte Software 4 05-19-07 17:50
Javascript Uproot Software 2 01-22-06 16:47
JavaScript help. Publius Software 0 12-02-05 11:06
javascript man_im_bored Software 1 12-21-03 21:46


All times are GMT -5. The time now is 02:19.

MajorGeeks.Com Menu

MajorGeeks.Com \ All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ NEW! PC Games \ System Tools \ Macintosh \ Demonews.Com \ Top Downloads

MajorGeeks.Com \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds


All content Copyright MajorGeeks.com source code Powered by vBulletin® Version 3.8.4
Copyright © 2009 vBulletin Solutions, Inc. All rights reserved.
Ad Management by RedTyger