简体   繁体   English

服务器标记在ASP控件中不起作用

[英]Server tags not working inside asp controls

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 值将放入.ascx的隐藏字段中,并在页面加载期间填充(如果没有,则回传)
  • one set of calendar extenders is in the item template field of a grid view call this set A 一组日历扩展器位于网格视图的项目模板字段中,称为该组A
  • the others are in a normal html table - set b 其他的都在普通的html表中- 设置b

set a and set b have flags StartDate="<%# hfStart.value%>" EndDate="<%# hfEnd.value%>" set a和set b具有标志StartDate="<%# hfStart.value%>" EndDate="<%# hfEnd.value%>"

set a in the item template of a grid view column works like a charm 在网格视图列的项目模板中设置a就像一个超级按钮

set b in the HTML table doesn't appear to work at all HTML表格中的set b似乎根本不起作用

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 具有<%:和<%=标记的CDate(hfstart.value).ToString
  • <%= 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. 除非我误会,否则<%=会在asp.net生命周期的末尾触发,从而阻止它在这种情况下有用。

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. 事实证明,您确实需要在asp标记中使用<%# %> ,就像其他类似<% %><%= %>的代码在ASP.NET生命周期结束时执行,并吐出缓冲区,这真是天知道哪里。 When using <%# %> however, the asp control needs to be DataBound(); 但是,使用<%# %>时,asp控件需要为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. 对于在gridview的<item template>标记中建模的控件,这种情况会自动发生,因为gridview中的所有内容都绑定在其gridview.DataBound()命令上。

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. 这将解释它们为什么在GridView中工作的原因,因为它支持数据绑定。

However in a basic HTML table you should use <% %> tags instead, or <%= %> to call a method. 但是,在基本HTML表中,应改为使用<% %>标记,或使用<%= %>来调用方法。

For full details of the tag types, try this reference . 有关标记类型的完整详细信息,请尝试参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM