我正在ASP.Net应用程序中使用jQuery创建一个弹出窗口。弹出按钮单击时打开。我已经编写了以下代码来打开弹出窗口。
html代码:
<%-- Popup --%>
<div id="modal_dialog" class="PopupStyle" style="display: none;">
<table>
<tr>
<td style="width: 100px">
<label class="control-label">Photo</label>
</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:RegularExpressionValidator
ID="regexValidateImageFil" runat="server" ControlToValidate="FileUpload1"
ErrorMessage="Only file types with jpg, png, gif are allowed."
ValidationExpression="^([0-9a-zA-Z_\-~ :\\])+(.jpg|.JPG|.jpeg|.JPEG|.bmp|.BMP|.gif|.GIF|.png|.PNG|.pdf)$"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td style="width: 100px">
<label class="control-label">File Type</label>
</td>
<td>
<asp:DropDownList ID="ddlUpFileType" runat="server" class="form-control" Width="400px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 100px">
<label class="control-label">Note</label>
</td>
<td>
<asp:TextBox ID="txtNotes" runat="server" class="form-control" MaxLength="150" Width="400px"></asp:TextBox>
</td>
</tr>
</table>
<div style="padding: 10px">
</div>
<asp:Button ID="btnSaveUpoad" runat="server" class="btn btn-primary" Text=" Upload File " OnClick="btnSaveUpoad_Click" />
</div>
</form>
</div>
和jQuery代码:
<script type="text/javascript">
$(document).ready(function () {
$("[id*=btnUpoad]").on("click", function () {
debugger;
$("#modal_dialog").dialog({ width: 520 });
$("#modal_dialog").dialog({
title: "Upload Files",
buttons: {
Close: function () {
$(this).dialog('close');
}
},
modal: true
});
return false;
});
});
</script>
正如您所看到的,html中有一个按钮,即
<asp:Button ID="btnSaveUpoad" runat="server" class="btn btn-primary" Text=" Upload File " OnClick="btnSaveUpoad_Click" />
但是click事件(来自弹出窗口中的按钮,即btnSaveUpoad)没有调用.cs文件中写入的相应函数。
任何想法。
提前致谢。
帕塔
答案 0 :(得分:0)
你的onclick没有调用该函数,因为你缺少()
来调用它
更改
OnClick="btnSaveUpoad_Click"
要
OnClick="btnSaveUpoad_Click()"
答案 1 :(得分:0)
在点击事件上使用Jquery进行绑定。另外,我建议您在模型完全加载后创建按钮事件f。
$( "#dataTable tbody tr" ).on( "click", function() {
console.log( $( this ).text() );
})
创建并显示模态。您可以在以下函数中添加要初始化的事件
$( "#code" ).on('shown', function(){
alert("I want this to appear after the modal has opened!");
});
答案 2 :(得分:0)
Try this for your solution:
$(document).on("click", "[id*=btnUpoad]",function () {
这可能对您有用。
jQuery 表现不同 当您直接使用 class 分配任何按钮事件时,它仅适用于 DOM 中的当前类,但如果假设在 DOM 中添加了新的 Document 内容并且您想在该新添加的 DOM 元素上触发 click 事件。那你就得用这个
*For current DOM
jQuery(".abc").click(function(){});*
*For dynamic dom element
jQuery(document).on("click", ".abc", function(){});*