JQuery模式弹出窗口
我正在尝试在asp.net页面上单击按钮后显示modalpopupJQuery模式弹出窗口,jquery,asp.net,jquery-ui,modal-dialog,Jquery,Asp.net,Jquery Ui,Modal Dialog,我正在尝试在asp.net页面上单击按钮后显示modalpopup <%@ Control Language="C#" AutoEventWireup="true" CodeFile="TestFile.ascx.cs" Inherits="TestFile" %> <%@ Import Namespace="System.Collections.Generic" %> <%@ Import Namespace="System.IO" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TestFile.ascx.cs" Inherits="TestFile" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.IO" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>jQuery UI Example Page</title>
<link type="text/css" href="css/ui-lightness/jquery-ui-1.8.21.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript">
function fnmodalpopup() {
$( "#dialog-modal" ).dialog({
height: 140,
modal: true
});
</script>
</head>
<!--Misc functions for operations -->
<script runat="server" type="text/javascript">
</script>
<div id="dialog-modal" title="Basic modal dialog">
<p>Adding the modal overlay screen makes the dialog look more prominent because it dims out the page content.</p>
</div>
<asp:Button ID="Button1" runat="server" Text="Button" />
jQueryUI示例页面
函数fnmodalpopup(){
$(“#对话框模式”).dialog({
身高:140,
莫代尔:对
});
添加模式覆盖屏幕使对话框看起来更加突出,因为它使页面内容变暗
,但在asp.net窗体中通过单击按钮触发。页面将闪烁,但不会显示任何内容
任何反馈都会非常有用!尝试更改
<asp:Button ID="Button1" runat="server" Text="Button" />
试试这个。它可以防止使用jQuery发回帖子。我以前对returnfalse方法有过一些问题
$(function () {
$("[id$=Button1]").click(function () {
// prevent the default action, e.g., following a link
event.preventDefault();
$dialog.dialog('open');
});
});
也可以考虑使用其他HTML对象,如果按钮点击不需要ASP.NET功能。它可以清理一些东西,防止你与服务器抗争。
你应该使用OnclitCutton事件,然后防止带有“强>返回false < /强>的回发:这样:
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return fnmodalpopup()" />
function fnmodalpopup() {
$( "#dialog-modal" ).dialog({
height: 140,
modal: true
});
return false;
});
函数fnmodalpopup(){
$(“#对话框模式”).dialog({
身高:140,
莫代尔:对
});
返回false;
});
编辑:
我已更改OnClientClick=“returnfnmodalpopup()”
现在它工作正常(至少当我测试它时)
好奇的是,如果您不想创建回发,为什么要使用服务器端组件?如果没有这种情况,当这个按钮必须执行回发时,也许最好使用html按钮标记(或任何其他html标记,并用jQuery捕获“click”事件)。是否在页面的其余部分使用asp.net控件并不重要。在asp.net中,如果将脚本管理器拖到页面上,并将按钮放在“更新面板-内容模板”标记中,则此操作也会正常工作。由于Ajax更新面板默认情况下会在asp.net的封面下阻止回发,因此按钮的OnClient单击可以正常显示jquery弹出窗口。但这主要在按钮是提供丰富客户端体验的控件集的一部分的情况下非常有用,而不是一直发回(例如,在提供交互式客户端控制面板的usercontrol中)。试试这个
$(function () {
modalPosition();
$(window).resize(function () {
modalPosition();
});
$('.openModal').click(function (e) {
$('.modal, .modal-backdrop').fadeIn('fast');
e.preventDefault();
});
$('.close-modal').click(function (e) {
$('.modal, .modal-backdrop').fadeOut('fast');
});
});
function modalPosition() {
var width = $('.modal').width();
var pageWidth = $(window).width();
var x = (pageWidth / 2) - (width / 2);
$('.modal').css({ left: x + "px" });
}
请参阅:-
产品信息
身份证件
品名
产品价格
行动
更新产品
接近
你的问题是什么?你的问题是什么?你在哪里设置变量$dialog
?我想我不需要这个函数,因为我可以使用onclick事件。不过这是个好主意。你使用asp:按钮有什么原因吗?也就是说,是否有一些服务器端的逻辑正在进行?尝试了你的建议,只需重置原始页面位置。没有弹出窗口。好的,现在可以了。有人请投票给Goran(因为我没有足够的声誉)。谢谢!我必须把按钮放在更新面板中吗?不,按钮在任何地方都可以工作,你可能需要查找“停止asp:发回按钮”尽管-使用该选项可能会更好,但我不确定您是否计划在模式对话框后处理代码中的单击事件-因此我不知道什么最适合您请同时提供一个解释,说明这是如何解决问题的
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return fnmodalpopup()" />
function fnmodalpopup() {
$( "#dialog-modal" ).dialog({
height: 140,
modal: true
});
return false;
});
$(function () {
modalPosition();
$(window).resize(function () {
modalPosition();
});
$('.openModal').click(function (e) {
$('.modal, .modal-backdrop').fadeIn('fast');
e.preventDefault();
});
$('.close-modal').click(function (e) {
$('.modal, .modal-backdrop').fadeOut('fast');
});
});
function modalPosition() {
var width = $('.modal').width();
var pageWidth = $(window).width();
var x = (pageWidth / 2) - (width / 2);
$('.modal').css({ left: x + "px" });
}
<div class="container">
<div class="row">
<center><h2>Product Information</h2></center>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<input type="text" id="txtpname" placeholder="Product Name" class="form-control">
</div>
<div class="form-group">
<input type="text" id="txtpprice" placeholder="Product Price" class="form-control">
</div>
<input type="submit" id="btninsert" value="Insert" class="btn btn-primary">
</div>
</div>
<br />
<div class="row">
<div class="col-md-5">
<table id="ProductTable" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<td>ID</td>
<td>Product Name</td>
<td>Product Price</td>
<td>Action</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<div id="mmd" class="modal fade" role="dialog">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="modal-header">
<h3>Update Product</h3>
</div>
<div class="modal-body">
<input type="hidden" id="hdnID" value="0" />
<div class="form-group">
<input type="text" id="txtuppname" placeholder="Product Name" class="form-control">
</div>
<div class="form-group">
<input type="text" id="txtuppprice" placeholder="Product Price" class="form-control">
</div>
</div>
<div class="modal-footer">
<input type="submit" id="btnupdate" value="Update" class="btn btn-primary">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>