Simple question, I know, but I can't seem to find a way to put both single and double quotes into the string of the text property of a Literal in asp.net
<asp:Literal runat="server" id="Literal1" Text="This is my "text", isn't it pretty" />
For example, in the above code snippet. The string closes on the first double-quote around 'text'. I know I could replace them with single quotes (or use all double quotes and wrap the string in single quotes), but I'm not sure how to use both. Escaping the quotes doesn't seem to work.
Setting the string on the code-behind is an option, of course, where I can escape the double quotes, but I've always thought it best to keep static text on the aspx, rather than cluttering the code-behind.
If you need to use the double quote inside the string, you can use the backslash character. Notice how the backslash in the second line is used to escape the double quote characters. And the single quote can be used without a backslash.
A string literal is bracketed by either single quotes ( ' ) or double quotes ( " ).
A single-quoted string does not have variables within it interpreted. A double-quoted string does. Also, a double-quoted string can contain apostrophes without backslashes, while a single-quoted string can contain unescaped quotation marks.
To place quotation marks in a string in your code In Visual Basic, insert two quotation marks in a row as an embedded quotation mark. In Visual C# and Visual C++, insert the escape sequence \" as an embedded quotation mark.
You can try the HTML enitity for the quotation mark: "
<asp:Literal runat="server" id="Literal1" Text="This is my "text", isn't it pretty" />
You can use:
<asp:Literal id="literal1" runat="server">This is my "text", isn't it pretty</asp:Literal>
This should work for you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With