EDIT1:
btnDelete.Attributes.Add("onclick", String.Format(@"return DeleteRow('{0}',{1},{2},{3});", e.Row.ClientID, e.Row.RowIndex, DataBinder.Eval(e.Row.DataItem, "Id"), "'" + DataBinder.Eval(e.Row.DataItem, "Name") + "'"));
edit:
i get this error:
Message: Unterminated string constant
i am passing the value from code behind and some of my text have somethinh lke this:
Foo3, In.c
//javascript
function DeleteRow(rowId, rowIdx, Id, Name) {
var textForMessage = "return confirm('Are you sure you want to delete this record with the name: \n{0} \n{1}');";
//removed code...
return result;
}
EDIT1:
btnDelete.Attributes.Add("onclick", String.Format(@"return DeleteRow('{0}',{1},{2},{3});", e.Row.ClientID, e.Row.RowIndex, DataBinder.Eval(e.Row.DataItem, "Id"), "'" + DataBinder.Eval(e.Row.DataItem, "Name") + "'"));
edit:
i get this error:
Message: Unterminated string constant
i am passing the value from code behind and some of my text have somethinh lke this:
Foo3, In.c
//javascript
function DeleteRow(rowId, rowIdx, Id, Name) {
var textForMessage = "return confirm('Are you sure you want to delete this record with the name: \n{0} \n{1}');";
//removed code...
return result;
}
Share
Improve this question
edited Feb 14, 2011 at 22:07
Nick Kahn
asked Feb 14, 2011 at 21:44
Nick KahnNick Kahn
20.1k97 gold badges284 silver badges416 bronze badges
4
|
5 Answers
Reset to default 11Do nothing. A comma has no special meaning inside a JavaScript string.
You don't need to escape the comma. You should surround the entire string with quotes:
'Foo3, In.c'
If this string is inside another string which is also single-quoted you may need to escape the quotes.
If the error is client side you can solve it by having:
btnDelete.Attributes["onclick"] = String.Format("return DeleteRow('{0}', '{1}', '{2}', '{3}');", e.Row.ClientID, e.Row.RowIndex, DataBinder.Eval(e.Row.DataItem, "Id"), DataBinder.Eval(e.Row.DataItem, "Name").ToString().Replace("'", "\'"));
If it's server side, please post the full error message plus stack trace.
\x2c
Useful in ajax.
function myfunction(id, str_URL) {
$.ajax({
type: "GET",
url: str_URL,
success: function(t) {
var link = "<a href=\x22JavaScript:MyJava(\x22Param1\x22\x2c\x22Param2\x22)\x22>Link text</a>";
}
});
}
\x22
is "
(quote)
Just reference the Hex column in the ascii table.
http://www.asciitable.com/index/asciifull.gif
If your trying to escape a throw error due to comas that you need in a non quoted could be string datatype. say you needed it that way post.example, + post.example,
var comma =",";
post.example.concat(comma) + post.example.concat(comma)
Using concat method will concatenate any variable type.
Foo3, In.c
then where is this value passed? Even if it is passed as one of the parameters, you are not doing anything with them... Please provide a more complete/correct/whatever example. – Felix Kling Commented Feb 14, 2011 at 21:50