Build script dynamically...

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?
 
A

Alex Davis

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.
 
A

Alex Davis

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".
 
I

Ivan Demkovitch

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top