ASP.NET custom server control cannot make binding expression work on properties
I got an issue which annoys me a lot... I have a custom server control which has a Text property. When I put that control inside the in repeater, listview, etc, for example, given the following markup:
<ItemTemplate>
<dl:SimpleLabel ID="lblTest" runat="server" Text='<%#Eval("FirstName")%>' />
</ItemTemplate>
When viewing it in browser, it ouputs <%Eval("FirstName")%>
in the source. Do I need to handle the binding in my server control 开发者_如何学C(the Text property already got the Bindable attribute set to true) or it should just work. What is the standard way of doing this?
Thanks in advance.
Cheers
Thanks Phaedrus.
Yeah I myself think it should work too. However I realise now I was kind of stupid I think... What I was doing is to use the following markup:
<dl:SimpleLabel ID="lblTest" runat="server" Text='Your name: <%#Eval("FirstName")%>' />
which does not work. However the following worked:
<dl:SimpleLabel ID="lblTest" runat="server" Text='<%#String.Format("Your name:{0}", Eval("FirstName"))%>' />
To me those two are the same but apparently the framework does different things in these cases.
Cheers
精彩评论