dmullis
asked on
Need syntax help - Cell.Text = <script Language = 'JavaScript'.........
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.a spx" onMouseOut="MM_swapImgRest ore()" onMouseOver="MM_swapImage( 'Contact US','','../images/controls /footer/co ntact_on.g if',1)"><i mg name="Contact US" border="0" src="../images/controls/fo oter/conta ct_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_swapImag e('Contact US','','../images/controls /footer/co ntact_on.g if' ,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/cont rols/foote r/AIS_49.g if'>"
+"<TR>"
+"<TD COLSPAN='2' vAlign='baseline' rowSpan='1'> "
+"</TD>"
+"<TD COLSPAN='18' bgcolor='#ffffff' background='../images/cont rols/foote r/AIS_49.g if' 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. We can communicate with you either over the phone or via email.</FONT></td>"
+"<td width='103'><a href='../pages/ContactUs.a spx' onMouseOut='MM_swapImgRest ore()'"
+"onMouseOver='MM_swapImag e('Contact US','','../images/controls /footer/co ntact_on.g if' ,1)'>"
+"<img name='Contact US' border='0' src='../images/controls/fo oter/conta ct_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.
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.a
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_swapImag
this.Rows[0].Cells.Add(new
this.Rows[0].Cells[0].Text
+"<TABLE WIDTH='751' BORDER='0' CELLPADDING='0' CELLSPACING='0' background='../images/cont
+"<TR>"
+"<TD COLSPAN='2' vAlign='baseline' rowSpan='1'> "
+"</TD>"
+"<TD COLSPAN='18' bgcolor='#ffffff' background='../images/cont
+"<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. We can communicate with you either over the phone or via email.</FONT></td>"
+"<td width='103'><a href='../pages/ContactUs.a
+"onMouseOver='MM_swapImag
+"<img name='Contact US' border='0' src='../images/controls/fo
+"</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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You!
I never knew this. This will be a great help!
I never knew this. This will be a great help!
you can do \" and \\'
For example
string script = " alert(\"foobar\"); "
" -- will be interperted first
\" , ' -- will be interperted second
\\\", \\' -- will be interperted third