Programmatically adding a Panel control adds "body" to its ID

时间:2015-07-31 19:56:19

标签: c# html asp.net

So I have this code:

var pnl = new Panel() {
    CssClass = "tab-pane",
    ID = "tab_content_" + gymTypes.Rows[0]["stars"].ToString()
};
tab_content.Controls.Add(pnl);

The gymTypes.Rows[0]["stars"] returns 1 so the ID should be tab_content_1 however when I run the website and inspect element the ID is somehow body_tab_content_1.

Is there a reason for this?

1 个答案:

答案 0 :(得分:0)

ASP.NET changes the ID of your elements. It is a documented behavior. If you need the id to stay the same, you need to set the ClientIDMode attribute of your panel