How do i identify which dynamically generated button is clicked?

Posted by Mahe under ASP.NET on 7/13/2012 | Points: 10 | Views : 945 | Status : [Member] | Replies : 1
Hi All,

I have generated few dynamic buttons on click of another button.
when i click on one of the dynamically generated button, How do i identify which dynamically generated button is clicked?

Regards,
Mahe




Responses

Posted by: Premalatha on: 7/13/2012 [Member] Starter | Points: 25

Up
0
Down
http://www.codeproject.com/Questions/172557/identify-a-clicked-button-from-a-dynamically-creat
You will need to bind "click" to the jQuery "live" function/event for that to work. I would also recommend using either a special CSS class or id on the dynamically generated button. Here is the description of the live even from jQuery.com.

When you bind a "live" event it will bind to all current and future elements on the page (using event delegation). For example if you bound a live click to all "li" elements on the page then added another li at a later time - that click event would continue to work for the new element (this is not the case with bind which must be re-bound on all new elements).

<script type="text/javascript">
$(document).ready(function() {
//$(":button") would select all buttons
//.className would work on an button with a CSS Class assignment of ClassName
//Below shows how to do it on a specific ID
$("#MyNewButtonID").live("click", function(event) {
alert("Thanks for visiting!" + this.value);
});
});
</script>

Premalatha
Software Engineer

Mahe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response