---
title: "Access Asp.net control using $(this) within setTimeout()"  
description: "Access Asp.net control using $(this) within setTimeout()"  
author: "Anonymous User"  
published: 2014-11-10  
updated: 2014-11-11  
canonical: https://www.mindstick.com/forum/2556/access-asp-dot-net-control-using-this-within-settimeout  
category: "asp.net"  
tags: ["jquery", "javascript"]  
reading_time: 1 minute  

---

# Access Asp.net control using $(this) within setTimeout()

I have a list of HTML [controls](https://www.mindstick.com/articles/66/how-to-create-controls-at-run-time-in-csharp-dot-net) and I need to bind a listener for the keyup event to each of these. Once that is triggered, some other [actions](https://www.mindstick.com/forum/156060/what-are-the-actions-performed-by-sql-server) should subsequently be kicked off after a time delay. I'm using setTimeout for that.

```
$(".TextBoxClass").each(function () {  $(this).keyup(function () {    alert("Id = " + $(this));        setTimeout(function () {        alert("current Id = " + $(this))    }, 50);  })})
```

The first alert [message](https://www.mindstick.com/forum/12802/show-confirmation-message-yes-or-no-in-asp-dot-net) shows the correct id of the control which [triggers](https://www.mindstick.com/articles/337000/what-are-sql-triggers-and-ways-of-using-them-effectively) the keyup event. The second alert within the setTimeout says current id = [object][object].

How can I [access the control](https://www.mindstick.com/forum/294/problem-in-access-the-control-inside-the-user-control) within the setTimeout [callback function](https://www.mindstick.com/forum/157808/what-is-a-callback-function-and-how-is-it-used-in-javascript)?

## Replies

### Reply by Anonymous User

```
<div id="controls">
    <input class="TextBoxClass" type="text" value="1" id="id-1">
    <input class="TextBoxClass" type="text" value="2" id="id-2">
    <input class="TextBoxClass" type="text" value="3" id="id-3">
    <input class="TextBoxClass" type="text" value="4" id="id-4">
    <input class="TextBoxClass" type="text" value="5" id="id-5">
  </div>

$('#controls').on('keyup', '.TextBoxClass', function () {
  var $this = $(this);

  setTimeout(function(){
    // alert("current value = " + $this.val());
    alert("current element id = " + $this.attr('id'));
  }, 50);
});
```


---

Original Source: https://www.mindstick.com/forum/2556/access-asp-dot-net-control-using-this-within-settimeout

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
