简体   繁体   中英

Asp.net runat=“server” changes id

I have the following html, which I need to runat="server"

<h2 class="admin-manager-table-header" runat="server" id="hdrBorrower">Borrower</h2>

I then have the following CSS:

.admin-manager-table-header#headerPending, .admin-manager-table-header#hdrBorrower {
    background-color: rgb(0, 176, 240);
}

Which no longer works as the server has changed the id to:

ctl00_body_hdrBorrower

So my CSS is now

.admin-manager-table-header#headerPending, .admin-manager-table-header#hdrBorrower , .admin-manager-table-header#ctl00_body_hdrBorrower{
    background-color: rgb(0, 176, 240);
}

My question is two fold:

1.Will the server always change the id to this, or will it sometimes vary the ID?

2.If it is consistent in its naming of the ID, is it bad practice of me to use this ID in a CSS style sheet?

Normally, it's subject to change based on the location of the node within the DOM (as seen by the server before responding to the client). There are two slightly different algorithms .NET can use for generating the ID. See Control.ClientIDMode .

As of .NET 4.0, I believe you can make your hand-picked ID "stick" using a ClientIdMode attribute of Static .

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