1

通常,Web 控件的未知属性会传递到浏览器中呈现的元素。所以以下工作。

<asp:label runat="server" Text="Label Text" helpId="101" />

但是,如果您使用如下的命名空间属性

<asp:label runat="server" Text="Label Text" myNs:helpId="101" /></div>

即使在 html 元素中声明了自定义命名空间,该属性也不会呈现给客户端,例如:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:myNs="http://www.acme.com/htmlext">

有谁知道无需使用自定义控件即可将其呈现给客户端的方法。模块或其他全局“可插拔”解决方案是可以接受的。

4

1 回答 1

0

在 MSDN 上找到这篇文章......看起来很有希望。但是您将需要创建一个自定义 Web 控件。

WebControl.AddAttributesToRender 方法

将需要呈现的 HTML 属性和样式添加到指定的 HtmlTextWriterTag。

[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
  protected override void AddAttributesToRender(HtmlTextWriter writer) 
  {

     writer.AddAttribute("myNs:helpId", "101");
     base.AddAttributesToRender(writer);

  }
于 2010-08-24T21:28:33.333 回答