HtmlGenericControl and id

ぃ、小莉子 提交于 2020-01-16 00:37:48

问题


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


回答1:


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




回答2:


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




回答3:


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).



来源:https://stackoverflow.com/questions/3496448/htmlgenericcontrol-and-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!