Build script dynamically...

  • Thread starter Thread starter Ivan Demkovitch
  • Start date Start date
I

Ivan Demkovitch

Hi!

Here is my problem: I'm inserting script for Trust Logo from one of the SSL
authorities.
It works fine when I do it in HTML, but I need to build it dynamically:

HtmlTableRow tR = new HtmlTableRow();
HtmlTableCell tC1 = new HtmlTableCell();
tC1.Controls.Add(new LiteralControl("<script
type=\"text/javascript\">TrustLogo(\"https://" +
ConfigurationSettings.AppSettings["DomainName"] +
"/images/secure_site.gif\", \"SC\", \"none\");</script>"));
tR.Cells.Add(tC1);


This doesn't work, gives me error:
CS1010: Newline in constant

How do I do it?
 
The problem is when you are building your javascript... Try this...

HtmlTableRow tR = new HtmlTableRow();
HtmlTableCell tC1 = new HtmlTableCell();

// Type the statement as a single line vs multiple... Or you can build a
string var for visibility sake... See below.
tC1.Controls.Add(new LiteralControl("<script
type=\"text/javascript\">TrustLogo(\"https://" +
ConfigurationSettings.AppSettings["DomanName"] + "/images/secure_site.gif\",
\"SC\", \"none\");</script>"));

tR.Cells.Add(tC1);

// For readability...
String jscript;

Jscript = "<script type=\"text/javascript\">";
Jscript += "TrustLogo(\"https://";
Jscript += ConfigurationSettings.AppSettings["DomanName"];
Jscript += "/images/secure_site.gif\", \"SC\", \"none\");"; Jscript +=
"</script>"

tC1.Controls.Add(new LiteralControl(Jscript));

Hope this helps.
 
Well I know that sometimes when I try to build a string and seperate the
lines (pressing enter key mid string), the enter key places a \n (newline)
character in the string. I just looked at my last reply and I do see it
serperated.... It supposed to be a single line of code vs multi for building
the "literal" string. I agree with you, logically placing the '+' between
breaks should do the trick but it dont sometimes...

Also, I remember one time where I copied and pasted a string from a word
doc, placed the string all on one line... and still get the error. That was
because the \n charcter was still in the string... You just could not see
it.

For example:
I copied the leteral string from the last reply I sent...

"<script
type=\"text/javascript\">TrustLogo(\"https://" +
ConfigurationSettings.AppSettings["DomanName"] + "/images/secure_site.gif\",
\"SC\", \"none\");</script>"

Pasted it into my code and get the error "Newline in constant"... then I
cleaned it up and it was fine. Unfortunatly, there is no good way of
finding the "newline".
 
Well..
Wasn't able to make it work ...

I steel use hardcoded script.

Also, I do not use VS, I use WebMatrix and this is almost just plain text
editor.
Looked over and over without any luck.

Is there any way to do <%# %> in script to insert my data?


Alex Davis said:
Well I know that sometimes when I try to build a string and seperate the
lines (pressing enter key mid string), the enter key places a \n (newline)
character in the string. I just looked at my last reply and I do see it
serperated.... It supposed to be a single line of code vs multi for building
the "literal" string. I agree with you, logically placing the '+' between
breaks should do the trick but it dont sometimes...

Also, I remember one time where I copied and pasted a string from a word
doc, placed the string all on one line... and still get the error. That was
because the \n charcter was still in the string... You just could not see
it.

For example:
I copied the leteral string from the last reply I sent...

"<script
type=\"text/javascript\">TrustLogo(\"https://" +
ConfigurationSettings.AppSettings["DomanName"] + "/images/secure_site.gif\",
\"SC\", \"none\");</script>"

Pasted it into my code and get the error "Newline in constant"... then I
cleaned it up and it was fine. Unfortunatly, there is no good way of
finding the "newline".

Ivan Demkovitch said:
Hi!

Here is my problem: I'm inserting script for Trust Logo from one of the SSL
authorities.
It works fine when I do it in HTML, but I need to build it dynamically:

HtmlTableRow tR = new HtmlTableRow();
HtmlTableCell tC1 = new HtmlTableCell();
tC1.Controls.Add(new LiteralControl("<script
type=\"text/javascript\">TrustLogo(\"https://" +
ConfigurationSettings.AppSettings["DomainName"] +
"/images/secure_site.gif\", \"SC\", \"none\");</script>"));
tR.Cells.Add(tC1);


This doesn't work, gives me error:
CS1010: Newline in constant

How do I do it?
 
Back
Top