Reference ASP.NET control by ID in JavaScript?

前端 未结 9 1216
孤街浪徒
孤街浪徒 2020-11-28 09:25

When ASP.NET controls are rendered their ids sometimes change, like if they are in a naming container. Button1 may actually have an id of ctl00_ContentMai

9条回答
  •  清歌不尽
    2020-11-28 10:29

    I do something similar to Rex M except to avoid multiple script tags I use a function in my page base class to register the controls I am going to use clientside, then spit them out to html inside 1 script tag.

    You could even subclass your controls to automatically register with the function or use a boolean property to set whether you are going to use them clientside.

提交回复
热议问题