惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
Help Net Security
Help Net Security
The Hacker News
The Hacker News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
V
Vulnerabilities – Threatpost
A
Arctic Wolf
T
Tor Project blog
Jina AI
Jina AI
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cyber Attacks, Cyber Crime and Cyber Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Spread Privacy
Spread Privacy
Security Latest
Security Latest
Latest news
Latest news
Last Week in AI
Last Week in AI
博客园 - 司徒正美
P
Privacy International News Feed
T
Tenable Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
腾讯CDC
博客园 - 聂微东
Scott Helme
Scott Helme
爱范儿
爱范儿
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
I
Intezer
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LINUX DO - 热门话题
有赞技术团队
有赞技术团队
S
Secure Thoughts
WordPress大学
WordPress大学
The Cloudflare Blog
AWS News Blog
AWS News Blog
B
Blog RSS Feed
Cyberwarzone
Cyberwarzone
S
Security Affairs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
The Register - Security
The Register - Security
L
LINUX DO - 最新话题
博客园_首页
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 【当耐特】
T
Troy Hunt's Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Securelist
S
Schneier on Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog

博客园 - 沐枫

git+svn 中文文件名乱码的处理 发展国产基础软件以及反盗版的异想 ASP.NET 日期数据服务端验证失败的原因 Mvc 2.0 Preview2 中 DefaultParameterValue 不支持枚举的Bug 推荐一个不错的flex ajax javascript资源网站 .net winform 的 OnKeyDown 与 方向键 MySQL 5.1 无法创建、修改存储过程的解决(简单问题) 一个稍微好用些的 svn 服务器 VC中的一个很奇怪的问题--关于C4244 汉语编程++ 关于Array.IndexOf 从赋值到初始化 从for到foreach 关注C++0x: Concept Ultimate Toolbox 开源了 关于C#2.0编译器的一个瘕疵 VC2008 beta2 的几个新东西 C++指针探讨 (四) 函数对象 boost 1.34 终于简化了内嵌python的支持
DynamicControl/DynamicField 例外的解决
沐枫 · 2009-01-21 · via 博客园 - 沐枫

  在使用 DynamicField / DynamicControl 时,经常在PostBack时,会出现一个例外:

  The DynamicControl/DynamicField needs to exist inside a data control that is bound to a data source that supports Dynamic Data.

  中文为:

  绑定到支持动态数据的数据源的数据控件内必须存在 DynamicControl/DynamicField

  具体发生原因暂时不太清楚,估计是PostBack的事件流程和页面正常加载不一致。当PostBack后,数据控件(如DetailsView, GridView, ListView 等)在状态加载时, 会把所有的 Fileds或Columns初始化一次,而这一次,由于数据源没有绑定,所以找不到相关的 MetaTable。在这种情况下,DynamicControl 和 DynamicField 都是丢出上述的例外。

  不过,从应用上来看,如果数据绑定做的合理的话(比如在InitComplete以前绑定),是不会出现这个问题的。但是一旦出了这个问题,解决起来就比较麻烦了,因为常常有些人习惯于在Load中绑定数据,要修改的话,常常会牵连一大堆的代码。希望对这个问题比较了解的朋友多多指教。

  目前我采用的方法,可以不改变原有的绑定流程,可以跟以前的Eval、Bind等一样使用,可以让大家试试。在使用中如有发现有Bug,请发邮件告诉我。因为我最近几个月都在应用 DynamicFieldTemplates 来开发应用程序,对这些问题比较关心。

  使用这种方法,可以让一些程序经验不足的人,也能避开这个错误。

  我分别从DynamicControl 和 DynamicField 继承了新的类 DdControl 和 DdField,然后在初始化时,判断是否存在MetaTable,如果不存在,则不再初始化。然后,程序中原本所有采用 DynamicControl/DynamicField的地方,都换成DdControl/DdField。

  DdControl/DdField的源码如下:

namespace Common
{
    
public class DdField : DynamicField
    {
        
public override void InitializeCell(System.Web.UI.WebControls.DataControlFieldCell cell, System.Web.UI.WebControls.DataControlCellType cellType, System.Web.UI.WebControls.DataControlRowState rowState, int rowIndex)
        {
            
// HACK: Fix bug for: The DynamicControl/DynamicField needs to exist inside a data control that is bound to a data source that supports Dynamic Data.
            if (base.Control.FindMetaTable() == null)
                
return;base.InitializeCell(cell, cellType, rowState, rowIndex);
        }

    }
}

namespace Common
{
    
public class DdControl : DynamicControl
    {
        
protected override void OnInit(EventArgs e)
        {
            
// HACK: Fix bug for: The DynamicControl/DynamicField needs to exist inside a data control that is bound to a data source that supports Dynamic Data.
            if (this.FindMetaTable() != null)
                
base.OnInit(e);
        }
    }
}

  使用时,只要在web.config中配置好前缀,就可以直接使用了。如:

<!-- 假设上述的程序生成 Common.dll -->
<add tagPrefix="asp" namespace="Common" assembly="Common"/>

<DetailsView >
  
<Fields>
    
<asp:DdField DataField="Name" />
    
  
</Fields>
</DetailsView>