I want to check some condition when a particular button is clicked how to do this?
$(document).ready(function () {
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
Search("Other");
});
function InitializeRequest(sender, args) {
}
function EndRequest(sender, args) {
alert(sender._postBackSettings.sourceElement.id)
var str1 = new String(sender._postBackSettings.sourceElement.id);
if (sender._postBackSettings.sourceElement.id == ContentPlaceHolder1_btnNew) {
alert("You have clicked new")
Search("NEW");
}
else {
alert("OTHERS")
Search("Other");
}
}
I got the solution by assigning it to a string value and checking in if condition as string.
Try this code :
Read this link: http://api.jquery.com/click/
If you have plenty of buttons, give them a same class name. Eg : class="myButton" The information regarding the particular button can be kept in its attribute. Eg : objectId="12345" then your code can come as follows :
If your buttons are being dynamically created, you can use this
live is deprecated for versions above Jquery 1.7.2.
You can use "on" instead of it.