我希望能在代码后端(code-behind)中从服务器控件(server control)调用MyMethod,就像下面这样:
如果我在aspx页面中使用
MyPage.aspx
<asp:Label ID="MyLabel" runat="server" Text='<%# MyMethod(Eval("MyColumn")) %>'>
MyPage.aspx.cs
protected void MyMethod(object obj) { ... }
如果我在aspx页面中使用
"
而不是'
,那么将会给我一个编译错误,错误提示为The server tag is not well formed.如下所示。<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
我想知道为什么需要使用单引号,这是一个规则吗?在我的情况下如何使用双引号?