rick schott
rick schott

Reputation: 21117

When must inline params for UserControls have single quotes to be well formed?

I have been just using what it wants for years and have never questioned it, however, can someone tell me why I have to use single quote vs double quotes in order to be a well formed tag?

Error Msg: "The server tag is not well formed."

What are the rules for the single quote enforcement(ie: within a template...etc)?

 //not well formed
 <uc1:blaControl ID="bla" runat="server" Prop1="<%# Eval("Data") %>" />

vs

 //well formed
 <uc1:blaControl ID="bla" runat="server" Prop1='<%# Eval("Data") %>' />
 <asp:Literal ID="ControlTitle" runat="server" Text="<%# Title %>" />
 <asp:Literal ID="ControlTitle" runat="server" Text='<%# Title %>' />

Upvotes: 1

Views: 147

Answers (2)

TheCodeKing
TheCodeKing

Reputation: 19220

Well the markup in the first is not valid SGML. The " inside the attribute are confused with the surrounding quotes so it's not clear where the attribute begins an ends. To get around this you need to keep them different.

// valid and will compile
<uc1:blaControl ID="bla" runat="server" Prop1='<%# Eval("Data") %>' />

The reason you can't alternatively use the following syntax which would be valid SGML, is that the C# inside the outer quotes becomes invalid and won't compile (single quotes denote a char).

 // valid but won't compile
 <uc1:blaControl ID="bla" runat="server" Prop1="<%# Eval('Data') %>" />

Upvotes: 2

Luis
Luis

Reputation: 6001

Xml allows you to use either single or double quotes for atributtes, by using a single quotes in the attribute declaration it means that then you can use double quotes inside the attribute value when you do for instance: Eval("something")

Upvotes: 0

Related Questions