i’m having the following problem.
I’ve a ASPX page with no databound and the following syntax:
<asp:label runat=server.... text='<%# MyFunction("parameter") %>' />
MyFunction is declared as follow:
protected function MyFunction(par as string) as string
if par = "1" then
MyFunction="something"
else
end if
end function
But ASP.NET don’t evaluate MYFUNCTION .
What’s i’m going wrong ?
<%#is used for data binding expressions. Typically you’ll see<%# Eval("FieldName") %>. If you’re trying to call a method defined in your code-behind, you should use<%= MyFunction("param") %>That said… you should consider a different approach. It would be better to do something as follows (using your existing example):
along with the following in your code-behind:
This approach ensures that your UI declaration knows nothing about methods defined on your code-behind, increasing the overall maintainability of your system.