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.

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top