HtmlGenericControl and id
Asked Answered
P

3

1

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

Panamerican answered 16/8, 2010 at 19:12 Comment(0)
Z
2

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

Zwinglian answered 16/8, 2010 at 19:32 Comment(3)
Thanks it's working fine, in my case it's was not the AddAttribute like the example but the WriteAttribute. ThanksDemarche
:( And this is why link-only answers are bad. Link is now broken.Toothwort
Sorry about that, I wrote the comment about 6 years ago however I did find a reference to the page on wayback machine. Probably a bit out of date now :) web.archive.org/web/20110122003516/http://www.bytechaser.com/en/…Zwinglian
T
1

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

Teyde answered 16/8, 2010 at 19:14 Comment(0)
E
1

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

Enedina answered 16/8, 2010 at 19:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.