What's the best way to deal with ASP.NET's ClientID

后端 未结 4 1902
闹比i
闹比i 2021-01-15 03:55

I\'m trying to find the best way to deal with the way that ASP.NET prepends a value to any element that is created with runat=\"server\", without having to reso

4条回答
  •  醉话见心
    2021-01-15 04:08

    The right answer is as follow

    var txt1 = $('#<%= txt1.ClientID %>');
    $(txt1).click(function () {
        alert('hi');
    });
    

    her I create a new variable on the javascript which is reference to the control based on its rendered client ID

提交回复
热议问题