Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Newline detected when add script in C# (ASP.NET)

Reply
Thread Tools

Newline detected when add script in C# (ASP.NET)

 
 
Ivan Demkovitch
Guest
Posts: n/a
 
      11-05-2003
Hi!

I'm trying to add script to the page and place following code in my ascx
(control):


Page.RegisterClientScriptBlock("adder", "<script>function
doadd(){document.all.TextBox3.value=eval(document. all.TextBox1.value) +
eval(document.all.TextBox2.value)}</script>");

It doesn't work giving me all kind of problems...

I suspect the problem is with <> charachters.

How do I go around this problem?

Also, placing this line in code (I use WebMatrix) will mess up all HTML
code??

Thanks!


 
Reply With Quote
 
 
 
 
Cliff Harris
Guest
Posts: n/a
 
      11-05-2003
If that is the exact line from your code, then it just has to do with how
your formed your string. You cannot insert a line break in a string in C#.
It should work if you change your code to read:

Page.RegisterClientScriptBlock("adder", "<script>function " +
"doadd(){document.all.TextBox3.value=eval(document .all.TextBox1.value) +
" +
"eval(document.all.TextBox2.value)}</script>");

or, for more readability, I always for my javascript in a temp variable
first. Just kinda hard to read otherwise

string script = "<script>function " +
"doadd(){document.all.TextBox3.value=eval(document .all.TextBox1.value) +
" +
"eval(document.all.TextBox2.value)}</script>"
Page.RegisterClientScriptBlock("adder", script);

either way, both of those should work for you.

-Cliff


"Ivan Demkovitch" <> wrote in message
news:...
> Hi!
>
> I'm trying to add script to the page and place following code in my ascx
> (control):
>
>
> Page.RegisterClientScriptBlock("adder", "<script>function
> doadd(){document.all.TextBox3.value=eval(document. all.TextBox1.value) +
> eval(document.all.TextBox2.value)}</script>");
>
> It doesn't work giving me all kind of problems...
>
> I suspect the problem is with <> charachters.
>
> How do I go around this problem?
>
> Also, placing this line in code (I use WebMatrix) will mess up all HTML
> code??
>
> Thanks!
>
>



 
Reply With Quote
 
 
 
 
Ivan Demkovitch
Guest
Posts: n/a
 
      11-05-2003
I solved problem...

Actually the problem was in "</script>"

Changed to "<" + "/" + "script>" and it works fine now.

Thanks!


"Cliff Harris" <> wrote in message
news:...
> If that is the exact line from your code, then it just has to do with how
> your formed your string. You cannot insert a line break in a string in

C#.
> It should work if you change your code to read:
>
> Page.RegisterClientScriptBlock("adder", "<script>function " +
> "doadd(){document.all.TextBox3.value=eval(document .all.TextBox1.value)

+
> " +
> "eval(document.all.TextBox2.value)}</script>");
>
> or, for more readability, I always for my javascript in a temp variable
> first. Just kinda hard to read otherwise
>
> string script = "<script>function " +
> "doadd(){document.all.TextBox3.value=eval(document .all.TextBox1.value)

+
> " +
> "eval(document.all.TextBox2.value)}</script>"
> Page.RegisterClientScriptBlock("adder", script);
>
> either way, both of those should work for you.
>
> -Cliff
>
>
> "Ivan Demkovitch" <> wrote in message
> news:...
> > Hi!
> >
> > I'm trying to add script to the page and place following code in my ascx
> > (control):
> >
> >
> > Page.RegisterClientScriptBlock("adder", "<script>function
> > doadd(){document.all.TextBox3.value=eval(document. all.TextBox1.value) +
> > eval(document.all.TextBox2.value)}</script>");
> >
> > It doesn't work giving me all kind of problems...
> >
> > I suspect the problem is with <> charachters.
> >
> > How do I go around this problem?
> >
> > Also, placing this line in code (I use WebMatrix) will mess up all HTML
> > code??
> >
> > Thanks!
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute a script from another script and other script does notdo busy wait. Rajat Python 3 01-08-2010 02:05 PM
RE: How to execute a script from another script and other script doesnotdo busy wait. VYAS ASHISH M-NTB837 Python 2 01-07-2010 08:18 PM
Add newline to Gridview cell John Doe ASP .Net Datagrid Control 1 04-28-2007 09:47 PM
Regular expression that doesn't recognize newline Antonio ASP .Net 0 01-19-2005 09:23 AM
IDE in HTML mode: newline after closing tag? Add In? Timo ASP .Net 1 04-23-2004 11:53 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57