Can someone explain to me the rules around what can and cannot be evaluated/inserted into markup using the <%# %> and <%= %> tags in asp.net?
When I first discovered I could inject code-behind variables into mark-up using <%= I thought ‘great’. Then I discovered that if such tags are present you can then not add to the controls collection of the page (that’s a whole different question!). But <%# tags are ok.
Is there a way I can inject a code-behind variable or function evaluation into the page using <%# ? Thanks.
The
<%#inline tag is used for data binding, so if you want to use a code-behind variable inside it, you will have to bind the page or control the variable resides in:You can include this statement in the
Page_LoadorPage_PreRenderevent.See this article for more information about the use of inline tags in ASP.Net, and this article for more about server-side databinding.