Triggering click with jQuery to hit code-behind function not working in 1.4 - Worked fine in 1.3.2
I have a gridview in an update panel and am using a jQuery dialog for adding entries.
The dialog calls an AJAX/JSON function that adds the entry. On success of that function I have jQuery trigger a button click on a hidden button
...
success: function(msg) {
$("[id$='_btnUpdateGrid']").trigger('click');
$("#new_dialog").dialog('close');
},
...
which should hit an event handler in the code behind to update the datasource and refresh the grid开发者_JS百科view.
<asp:Button ID="btnUpdateGrid" runat="server" OnClick="btnUpdateGrid_Click"
Text=" " Width="1px" Height="1px" Style="background-color:#F5F3E5; border:none;" />
This has worked just fine with 1.3.2. Updated to 1.4.1 and it no longer hits the code-behind. The AJAX still works but I have to manually refresh the page to update the grid.
Also, I can hit client side event handlers (e.g OnClientClick="alert('hello')") so I know the click is still happening just not the code-behind event handler. It's like jquery is somehow blocking the page from doing just that now. I have verified this by just changing the version number in the script reference path and seeing the functionality change.
Is this a bug or s there another way I'm supposed to do this now?
You might try changing ID to id or vice-versa. It could be a case-sensitive identifier issue.
Perhaps try binding the event handler to the buttons using JavaScript, instead of doing it with an onClick attribute in the HTML. jQuery lets you do that using live event bindings:
$("[id$='_btnUpdateGrid']").live("click", btnUpdateGrid_Click);
I'm not sure that'll do anything to solve the problem, but it's worth a try.
Turns out it was just the order. Not sure why 1.3 didn't mind the order but that's all it took.
...
success: function(msg) {
$("#new_dialog").dialog('close');
$("[id$='_btnUpdateGrid']").trigger('click');
},
...
works fine.
精彩评论