" or ' in control syntax?

  • Thread starter Thread starter Davids
  • Start date Start date
D

Davids

please can you save me hours of Googling by telling me the difference
between using ' or " in a control's parameters eg:
<asp:Label ID="BlogCategoryLabel" Runat="server" Text='<%#
Eval("BlogCategory") %>'/>

where these two are intermixed...
 
ouch just remembered a few secs later, it's for specifying Char (not String)
that is Unicode... right?
 
Davids said:
please can you save me hours of Googling by telling me the difference
between using ' or " in a control's parameters eg:
<asp:Label ID="BlogCategoryLabel" Runat="server" Text='<%#
Eval("BlogCategory") %>'/>

HTML wants double quotes, so that's what you should use.

Except where that doesn't work, which is inside of a data binding expression
or the like. There, you have to use single quotes where you would have used
double quotes.


John Saunders
 
read through the docs but there's no mention of ' ' they even document
using "";

<tagprefix:tagname property="<%# data-binding expression %>" runat="server"
/>
 
Davids said:
read through the docs but there's no mention of ' ' they even document
using "";

<tagprefix:tagname property="<%# data-binding expression %>"
runat="server" />

<asp:TextBox id="TextBox1" runat="server"
 
It will work either way. However, the build in visual designer gets
confused. When it sees:

<asp:Label Runat="Server" Text="<%# Eval("Test") %>" />

it sees the double quote in the Eval call to be terminating the Text
attribute.

The way I remember is: if the attribute will have a double quote, then use
single quotes to suround the attribute.

Happy coding,
Johann MacDonagh
 
Although not exactly know the reason why it'll pass, I think maybe it's
bacause the WebControls are passed to parser to reparse to HtmlControls. So
in the conversion process the error in syntax is corrected. (Most of the
trick in WebControls come from client-side script, and in javascript both "
" and ' ' are allowed)
 
Back
Top