How to call event for command button in the grid
I have va开发者_如何学运维rious command buttons in my Grid such as 'Insert', 'Update', etc.... I customize the Grid adding the buttons manually and placing ID's like btnInsert, btnUpdate, and so on. The buttons are shown when I click the 'Insert' or 'Update' image.
My issue is: How can I directly call the event handler for the above buttons? I just want to validate the inputs before the data is saved to the DB. Since the buttons are inside the Grid, I am finding it difficult to call the button's event handler. It would be nice to know of any ways this is possible.
I used the below code:
$('#btnUpdate').click(function(e)s {
alert('checking the fun');
e.preventDefault();
});
I also used the Update button's client ID:
$('#RadGrid1_ctl00_ctl05_btnUpdate').click(function(e){
//Input validation
});
-Thanks
You could take a look at the jquery documentation page about events: http://docs.jquery.com/Events
You could use one of these with something like: butonname.onclick( function() { //your validation here });
Can you post some of the HTML for the grid? That would really help us be able to help you.
My guess is that you will want to give all the update buttons a CLASS like btn-update. Then you can use javascript like this:
$(".btn-update").bind('click', function (event) {
event.preventDefault();
$btn = event.currentTarget; //$btn will be a jQuery object containing the button that was clicked
//call validate function
//send data to server
});
Is this what you want?
$('#btnInsert').click();
However, this is not the best style. The validation function shoud be a function of its own, then you can call it from the button event handler and other places alike.
精彩评论