Getting ID from asp.net runat server in jQuery

后端 未结 7 2282
执笔经年
执笔经年 2020-12-01 17:17

I\'m trying make some stuff in jQuery using ASP.NET. But the ID from runat=\"server\" is not the same as the id used in HTML.

I used to use this to get

7条回答
  •  甜味超标
    2020-12-01 17:35

    As others have mentioned, you can pass a class selector to jQuery, but that is a bit messy. I prefer to use the jQuery attribute ends with selector. Given that a generated ID is a flattened hierarchy of controls, you can use the "ends with" selector to find your element.

    
    

    When rendered, the generated ID becomes something like this (if within a masterpage's content place holder):

    
    

    To find this control:

    $("input[id$='txtText']")
    

    Take caution when using this within a repeater.

提交回复
热议问题