我想使用 jQuery 触发 ASP.NET 按钮
放置在 Updatepanel 中的目标按钮
jQuery代码:
$(document).ready(function () {
$('.ViewDetail').click(function (e) {
var ID = $(this).parent().parent().attr('ExpID');
$("#hflIdentityID").val(ID);
$("#btnLoadBills").trigger('click');
$("#ExpenseBills").dialog("open");
return false;
});
});
标记代码:
<asp:UpdatePanel ID="DetailBillUpdatepanel" runat="server">
<ContentTemplate>
<div id="btnLoadGrid" style="display: none;">
<asp:Button ID="btnLoadBills" ClientIDMode="Static" CausesValidation="false" runat="server"
Text="Button" />
</div>
GridView is Here...
</ContentTemplate>
</asp:UpdatePanel>
后台代码:
Protected Sub btnLoadBills_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoadBills.Click
grvExpenseBills.DataSource = tadok.Data.DataRepository.EdlBlpProvider.GetByEdlId(hflIdentityID.Value)
grvExpenseBills.DataBind()
End Sub
为什么事件没有触发?
最佳答案
将您的 jquery 事件处理程序绑定(bind)放入以下函数中
function pageLoad(sender,args) {
// binding code here, for example
$('#button').click(function(e) {
// do something when the click event is raised
});
}
pageLoad
在每次同步或异步回发后执行。 pageLoad 是 ASP.NET AJAX 中为此目的保留的函数名称。另一方面,$(document).ready()
仅在 DOM 最初准备好/加载时执行一次。
这取自this
关于jquery - 使用 jQuery 触发 Click 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6081740/