admin管理员组

文章数量:1225015

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
  • 2 Your code looks... strange. You define parameters which you don't use. You initialize a local variable which you don't use. And you return a variable which you have not defined... If the text you have is 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
  • i removed some of the code for readability – Nick Kahn Commented Feb 14, 2011 at 22:00
  • 1 But you've also removed any indication of an actual issue. Please post full code that demonstrates the issue, not merely the part that you assume represents whatever issue you're having. In other words, please provide a working example. – user113716 Commented Feb 14, 2011 at 22:04
  • 1 Your update doesn't look like javascript to me. – user113716 Commented Feb 14, 2011 at 22:12
Add a comment  | 

5 Answers 5

Reset to default 11

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

本文标签: aspnetHow to ESCAPE quotcommaquot in JavascriptStack Overflow