G
Guest
Overview: I want to know the best/easiest way to make arbitrary text data
safe for programmatic insertion into javascript.
Detail: I'm plotting database data onto maps by looping through my records,
building up a javascript statement using stringbuilder, and injecting that
into my page:
***
StringBuilder sb = new StringBuilder();
....[ORM stuff deleted] ..
foreach (Locations loc in locoll)
{
currlocstring = ("AddPin(" + loc.Latitude + "," + loc.Longitude
+ ",null,'" + loc.Name + "','" + loc.Name.Replace("''", "") + "');");
sb.Append(currlocstring);
}
string myScript = "<script type='text/javascript'> ... sb.ToString() + "
</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript",
myScript);
***
loc.Name is arbitrary data entered via a form. If the user enters script
characters like apostrophes, it breaks the rendered javascript. I am
wondering if there is an "all in one" sanitizer script inside or outside the
..NET framework that will handle all problematic characters.
Any help out there in netland?
Thank you,
-KF
safe for programmatic insertion into javascript.
Detail: I'm plotting database data onto maps by looping through my records,
building up a javascript statement using stringbuilder, and injecting that
into my page:
***
StringBuilder sb = new StringBuilder();
....[ORM stuff deleted] ..
foreach (Locations loc in locoll)
{
currlocstring = ("AddPin(" + loc.Latitude + "," + loc.Longitude
+ ",null,'" + loc.Name + "','" + loc.Name.Replace("''", "") + "');");
sb.Append(currlocstring);
}
string myScript = "<script type='text/javascript'> ... sb.ToString() + "
</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript",
myScript);
***
loc.Name is arbitrary data entered via a form. If the user enters script
characters like apostrophes, it breaks the rendered javascript. I am
wondering if there is an "all in one" sanitizer script inside or outside the
..NET framework that will handle all problematic characters.
Any help out there in netland?
Thank you,
-KF