Server tags not working inside asp controls

孤者浪人 提交于 2020-01-14 01:36:42

问题


Alrighty to make this quick:

  • I want to set start and end dates for a calendar extender dynamically on-change or on page load
  • the values are put into hidden fields on the .ascx and populated during page load in an if not postback
  • one set of calendar extenders is in the item template field of a grid view call this set A
  • the others are in a normal html table - set b

set a and set b have flags StartDate="<%# hfStart.value%>" EndDate="<%# hfEnd.value%>"

set a in the item template of a grid view column works like a charm

set b in the HTML table doesn't appear to work at all

What gives?

So far I have tried other server tags with the same code inside but I am obviously missing the salient detail. Why does one work and not the other?

UPDATE: Tried

  • CDate(hfstart.value).ToString with <%: and <%= tags
  • <%= hfstart.value %>

Unless I misunderstand, <%= will fire at the very END of the asp.net life cycle stopping it from being useful in this context.


回答1:


As it turns out you DO need to use <%# %> within asp tags as others like <% %> and <%= %> execute at the end of the ASP.NET life cycle and get spit out the buffer to god knows where. When using <%# %> however, the asp control needs to be DataBound(); at the appropriate time.

This happens automatically for controls modeled in the <item template> tags in the gridview because everything within the gridview is bound on its gridview.DataBound() command.




回答2:


Could it be because you're using the <%# %> tags which are for data binding? This would explain why they work in the GridView, because it supports data binding.

However in a basic HTML table you should use <% %> tags instead, or <%= %> to call a method.

For full details of the tag types, try this reference.



来源:https://stackoverflow.com/questions/19800526/server-tags-not-working-inside-asp-controls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!