Solved

Need syntax help  -    Cell.Text = <script Language = 'JavaScript'.........

Posted on 2004-10-19
3
396 Views
Last Modified: 2009-07-29
I have a C# server control that contains a footer. The footer code is HTML w javascript rollover events. (The HTML code also calls an exernal js file for it's functions). This code works fine from a  regular aspx page, so the actual code should not be the problem, just the syntax of trying to embed javascript this way. Because of using the HTML in this manner, I have to take out all inside double quotes("). This is causing a proplem when trying to insert the javascript code because 1 line of it already has embeded quotes, and in javascript you cannot embed the same type of quotes. Is there any work around for this? Here is the code:


The HTML part of the code below works as intented, but here is the original JavaScript(aspx) page code:
<td width="103"><a href="../pages/ContactUs.aspx" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Contact US','','../images/controls/footer/contact_on.gif',1)"><img name="Contact US" border="0" src="../images/controls/footer/contact_off.gif" width="119" height="43"></a></td>

                  
Here is what I am trying to do: The problem is probably with this line that already had embeded quotes- see original code above:       +"onMouseOver='MM_swapImage('Contact US','','../images/controls/footer/contact_on.gif' ,1)'>"            

this.Rows[0].Cells.Add(new TableCell());      
            
this.Rows[0].Cells[0].Text="<script language='JavaScript' src='http://localhost/PLTP/Scripts/ContactMeRollover.js'></script>"            
 +"<TABLE WIDTH='751' BORDER='0' CELLPADDING='0' CELLSPACING='0' background='../images/controls/footer/AIS_49.gif'>"
+"<TR>"
+"<TD COLSPAN='2' vAlign='baseline' rowSpan='1'>&nbsp;"
+"</TD>"
+"<TD COLSPAN='18' bgcolor='#ffffff' background='../images/controls/footer/AIS_49.gif' width='659'><table width='98%' border='0' cellspacing='0' cellpadding='0' align='center' height='67'><tr>"
+"<td colspan='3'><FONT face='Verdana' size='2'>Simply click on the Contact Us button and a licensed AIS representative will help you with your quote.&nbsp; We can communicate with you either over the phone or via email.</FONT></td>"
+"<td width='103'><a href='../pages/ContactUs.aspx' onMouseOut='MM_swapImgRestore()'"
+"onMouseOver='MM_swapImage('Contact US','','../images/controls/footer/contact_on.gif' ,1)'>"
+"<img name='Contact US' border='0' src='../images/controls/footer/contact_off.gif' width='119' height='43'>"
+"</a>"
+"</td>"
+"</tr>"
+"</table>"
+"</TD>"
+"</TR>"
+"</TABLE>";
Again, the overall code and the HTML code work as designed..the Javascript doesn't work. I have gotten javqscript to work in this manner before but I did not have to deal with double embeded quotes.



0
Comment
Question by:dmullis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Expert Comment

by:nitrogenx
ID: 12375622
you need to escape if you want to go below " and '

you can do \" and \\'

For example

string script = " alert(\"foobar\"); "

" -- will be interperted first
\" , ' -- will be interperted second
\\\", \\' -- will be interperted third
0
 
LVL 3

Accepted Solution

by:
nitrogenx earned 500 total points
ID: 12375636
To fix your code:

+"<td width='103'><a href='../pages/ContactUs.aspx' onMouseOut='MM_swapImgRestore()'"
+"onMouseOver=\"MM_swapImage('Contact US','','../images/controls/footer/contact_on.gif' ,1)\">"
+"<img name='Contact US' border='0' src='../images/controls/footer/contact_off.gif' width='119'
0
 

Author Comment

by:dmullis
ID: 12380669
Thank You!
I never knew this. This will be a great help!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question