.Net Changes the element IDs

前端 未结 5 1481
离开以前
离开以前 2020-12-19 19:03

.Net is kindly changing the element ids on my pages by appending a ct100_ to them. As much as I appreciate microsoft trying to help me keep from duplicating ids on my site,

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-19 19:44

    That's just how aspnet works. Controls provide the clientid method for you to use in your code behind for this reason.

    If you want to refer to objects from js, you can either inject the clientid or use classes or other attributes.


    Edit: Note that this only applies to the ASP.NET controls. If you use the HTML controls, the given IDs are preserved. You can access them in your code behind by adding the runat=server attribute to them, too. Obviously these controls break the webforms model with viewstate, etc. but they do give you your desired functionality.

    Of course it's been a while since I worried about it so I could be wrong...(please comment or edit if I am!).

提交回复
热议问题