2

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;
    }
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. Commented Feb 14, 2011 at 21:50
  • i removed some of the code for readability 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. Commented Feb 14, 2011 at 22:04
  • 1
    Your update doesn't look like javascript to me. Commented Feb 14, 2011 at 22:12

5 Answers 5

10

Do nothing. A comma has no special meaning inside a JavaScript string.

Sign up to request clarification or add additional context in comments.

1 Comment

Yup, you would want to escape single quotes though. You can escape single quotes with a "\" ... so ' becomes \' in the javascript that you emit.
2

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.

1 Comment

i have updated my question, i am passing the name with surround with single quotes.
0

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.

2 Comments

yes the error is at client side and if i comment the server side line code which is (btnDelete ....... ) than it works fine without any javascript error, but if uncomment the server side code than i do see the error ` Message: Unterminated string constant `
@Abu did you try with the exact line I posted instead of the line you have?
0

\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

1 Comment

using , instead of \x2c gives browser error Uncaught SyntaxError: Unexpected end of input
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.