Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between ' (single quote) and “ (double quote) in ASP.NET 4

Tags:

asp.net

I want to call MyMethod in code-behind from server control in aspx page like below.

MyPage.aspx

<asp:Label ID="MyLabel" runat="server" Text='<%# MyMethod(Eval("MyColumn")) %>'>

MyPage.aspx.cs

protected void MyMethod(object obj) { ... }

If I use " instead ' in aspx page then it will give me a compilation error The server tag is not well formed. as below.

<asp:Label ID="MyLabel" runat="server" Text='<%# MyMethod(Eval("MyColumn")) %>'> // This line work
<asp:Label ID="MyLabel" runat="server" Text="<%# MyMethod(Eval("MyColumn")) %>"> // This line error

I want to know why I need to use single-quote, is it a rule? How can I use double-quote in my situation?

like image 208
Anonymous Avatar asked Sep 15 '11 15:09

Anonymous


People also ask

What is the difference between single quotes and double quotes?

General Usage Rules In America, Canada, Australia and New Zealand, the general rule is that double quotes are used to denote direct speech. Single quotes are used to enclose a quote within a quote, a quote within a headline, or a title within a quote.

What is the difference between single and double quotation marks in coding?

As far as language syntax is concerned, there is no difference in single or double quoted string. Both representations can be used interchangeably. However, if either single or double quote is a part of the string itself, then the string must be placed in double or single quotes respectively.

What is the difference between single quote and double quote in C#?

The single quote is used to define a character literal. The double quote is used to define a string literal. Neither of them have any other purpose in the C# language.

Is there a difference between single and double quotes in JS?

Generally, there is no difference between using double or single quotes, as both of them represent a string in the end. There is only one difference in the usage of single and double quotes, and it comes down to what quote character you need to escape using the backslash character (\): \' or \”.


1 Answers

I want to know why I need to use single-quote, is it a rule? How can I use double-quote in my situation?

The use of Single quote over Double quote is just to make it clear where the string is ending. You cannot use Text="MyMethod("123")" because the Text start with the M and may end with the ( or the 3 or the last ). By using single and double quote the compiler know when the string end.

Text="MyMethod('123')"

Text='MyMethod("123")'

Your example is about binding but let say that you would like to have a double quote while using a double quote for a non-binding situation. You could have use the HTML entity "

Text="This is my string with  &quot; inside &quot;" //This will produce : This is my string with "inside"
like image 158
Patrick Desjardins Avatar answered Sep 19 '22 04:09

Patrick Desjardins