I have an ASP .NET page which contains dynamically created user controls (all instances of a single control) inside several repeaters. Each of these user controls contains, amongst other things, a text box which I want to blank out using an HTML button below it. As I don't want to cause any postbacks I'm attempting to do this all client-side using jQuery.
On the main page I have the following:
var removeCommentBtns = $('.remove-comment-btn');
for (let i = 0; i < removeCommentBtns.length; i++) {
if (removeCommentBtns.val() != null) {
removeCommentBtns[i].addEventListener("click", function () {
//blank out text box
})
}
};
This loops through all the buttons I want to add the text box clear event to, but I have had no luck working out what I need to put in the event listener to blank out the text box. I can't refer to the text box using $('#<%=txtTextBox.ClientID %>')
because the text box lives in my user control.
I've also tried various DOM manipulation things, such as finding the previous span where the text box is and setting the textContent $(this).prevAll('.span-clause-comment')[0].textContent = "";
but this causes the text box itself to disappear too.
I'm sure there is something fundamental that I'm missing!