$('#<%=nameLabel.ClientID%>') does not work when in .js file and works when in script is in the page

后端 未结 5 1304
再見小時候
再見小時候 2021-01-28 19:08

$(\'#<%=nameLabel.ClientID%>\') is being used in my script for jquery.

When this is in ... block in tha page , it works fine ,as its a content page i

5条回答
  •  迷失自我
    2021-01-28 19:38

    Simple answer : You can't use inline asp.net scripting in external .js files.

    But there are two articles and source code which make this possible :

    Simply click here and click here.

    And also Asp.NET 4.0 brings a nice solution to this problem which is called ClientIDMode

    Markup:  
    Output: 
    

    Markup:  
    Output: 
    

    Markup:   
    Output: 
    

    For more information, drop by here

提交回复
热议问题