简体   繁体   中英

c# - how to set specific control indentification in asp.net?

i desire to create ASP.NET control with specific identification with C#:

MyControl myControl = new MyControl { ID = "my-control" };

but after render, the identification become:

<div id="ctl13_my-control"> ... </div>

i desire for style sheet of cascade:

<div id="my-control"> ... </div> 

how to fix?

In ASP.NET 4 and above, you can set the ClientIDMode property to determine how the control's ID is rendered. For example using Static means whatever ID you give the control is what you will see in the HTML source.

您可以尝试设置ClientID属性:

MyControl myControl = new MyControl { ClientID = "my-control" };

You can do that with the property "clientidmode" set to "static"

<div id="my-control" clientidmode="Static"> ... </div> 

Been there, done that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM