[英]Unable to fire ButtonClick event from ModalPopUp
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/start/jquery-ui.css"
rel="stylesheet" type="text/css" />
Script 脚本
<script type="text/javascript">
$("[id*=btnModalPopup]").live("click", function () {
$("#modal_dialog").dialog({
title: "jQuery Modal Dialog Popup",
buttons: {
},
modal: true
});
return false;
});
</script>
Pop Up Div 弹出Div
<div id="modal_dialog" style="display: none">
<asp:FileUpload ID="FileUpload6" CssClass="CS" runat="server" />
<asp:Button ID="btnpopupupload" runat="server" Text="UPLOAD" onclick="btnpopupupload_Click"/>
</div>
Code Behind 背后的代码
protected void btnpopupupload_Click(object sender, EventArgs e)
{
}
I am able to fire buttonclick event when the same button is outside the modal_dialog
div. 当同一个按钮位于
modal_dialog
div之外时,我就可以触发buttonclick事件。
Try 尝试
$(document).on("click","[id*=btnModalPopup]" function () {
$("#modal_dialog").dialog({
title: "jQuery Modal Dialog Popup",
buttons: {
},
modal: true
});
return false;
});
Its better to give a class name for the button, because .net will change the id of your button while rendering 最好为按钮指定一个类名,因为.net会在渲染时更改按钮的ID
or You can use 或者您可以使用
$(document).on("click",".classname" function () {
$("#modal_dialog").dialog({
title: "jQuery Modal Dialog Popup",
buttons: {
},
modal: true
});
return false;
});
Try to use event delegation here: 尝试在此处使用事件委托 :
$('body').on("click", "[id*=btnModalPopup]"function () {
$("#modal_dialog").dialog({
title: "jQuery Modal Dialog Popup",
buttons: {
},
modal: true
});
return false;
});
Change your button control to link button control as below. 如下更改按钮控件以链接按钮控件。
<asp:LinkButton ID="btnpopupupload" runat="server" Text="UPLOAD" onclick="btnpopupupload_Click"/>
If the above solution not working, please add below code in your script. 如果上述解决方案不起作用,请在脚本中添加以下代码。
<script type="text/javascript">
$("[id*=btnModalPopup]").live("click", function () {
$("#modal_dialog").dialog({
title: "jQuery Modal Dialog Popup",
buttons: {
},
modal: true
}).parent().appendTo($("form:first"));
return false;
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.