0

I'm facing single quote (') issue inside RESX files while I call them directly in JavaScript, such as:

var hello = '<%=SomeTextFromResxWithSingleQuote%>';

In this case all the JavaScript is mixed up and many bugs appear :( Any fast solution to solve this? Thanks :)

Or Assayag
  • 5,662
  • 13
  • 57
  • 93

2 Answers2

1

You can use double quotes to skip this issue such as:

var hello = "<%=SomeTextFromResxWithSingleQuote%>";

JavaScript allows you to use either double or single quotes to delimit text.

When to use double or single quotes in JavaScript?

Community
  • 1
  • 1
Ghasan غسان
  • 5,577
  • 4
  • 33
  • 44
0

Solved.

string fixedText = ReplaceSingleQuote("L'df'ds");

public static ReplaceSingleQuote(string text)
{
        if (string.IsNullOrEmpty(text))
        {
            return text;
        }
        return text.Replace("'", "&apos;");
}
Or Assayag
  • 5,662
  • 13
  • 57
  • 93