HtmlGenericControl 和 id

发布于 2024-09-14 13:29:48 字数 125 浏览 3 评论 0原文

有一种方法可以控制我的 HtmlGenericControl 的 ID。

我尝试创建自己的 HtmlGenericControl 并覆盖 UniqueID、ClientID、onPreRender 等...但没有任何效果

It's there a way i can control the ID of my HtmlGenericControl.

I try to create my own HtmlGenericControl and override UniqueID, ClientID, onPreRender etc ... but nothing work

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小姐丶请自重 2024-09-21 13:29:48

下面的文章演示了如何覆盖您自己的 ID 控件。虽然它没有显示如何为 htmlgenericcontrol 执行此操作,但从所有其他示例中应该很容易弄清楚。

如何显示具有干净 ID 值的 Asp.Net 控件

The following article demonstrates how to override controls your own ID's. Whilst it does not show how to do it for htmlgenericcontrol it should be pretty easy to figure out from all the other examples.

How to Display Asp.Net Controls with Clean ID Values

站稳脚跟 2024-09-21 13:29:48

您不需要覆盖这一切,只需覆盖渲染并手动完成所有操作

You don't need to override this all, just override Render and do everything manually

再见回来 2024-09-21 13:29:48

可以通过添加 id 属性来手动为 HtmlGenericControl 指定客户端 Id:

var bob = new HtmlGenericControl("div")
{
    InnerHtml = "give me an Id!"
};

bob.Attributes.Add("id", "myId");

this.Page.Controls.Add(bob);

给定的 Id 只能从客户端(例如 JavaScript)访问。

The HtmlGenericControl can be manually given a client Id by adding the id attribute:

var bob = new HtmlGenericControl("div")
{
    InnerHtml = "give me an Id!"
};

bob.Attributes.Add("id", "myId");

this.Page.Controls.Add(bob);

The Id given will only be accessible from the client side (e.g. JavaScript).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文