Reputation: 2871
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.
Upvotes: 24
Views: 53601
Reputation: 71
I would like to suggest string.format...
...
Literal1.Text = string.format("{0}","This is my text, isn't it pretty?";
Upvotes: 0
Reputation: 7930
you can use double qoutes inside single quotes like this:
<asp:Literal runat="server" id="Literal1" Text='This is my "text", isnt it pretty' />
But if you want to use in text both of them, the best way to do this is in code behind
Upvotes: 4
Reputation: 9561
You can use:
<asp:Literal id="literal1" runat="server">This is my "text", isn't it pretty</asp:Literal>
This should work for you
Upvotes: 6
Reputation: 10812
I would suggest escape characters, but I'm not aware of a way to use those inline. Instead, use code to initialize the value.
<asp:Literal runat="server" id="Literal1" Text="" />
...
Literal1.Text = "This is my \"text\", isn't it pretty?";
Alternatively, you can use HTML encoding as suggested elsewhere.
<asp:Literal runat="server" id="Literal1" Text="Isn't "it" pretty?" />
Upvotes: 1
Reputation: 2295
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" />
Upvotes: 35