如何使用jQuery创建ASP.NET回发确认对话框?
我正在使用下面的代码获取Jquery UI弹出窗口,但它没有返回值,弹出框正在关闭 我需要当我点击按钮,它必须作为确认框工作 代码:如何使用jQuery创建ASP.NET回发确认对话框?,jquery,asp.net,Jquery,Asp.net,我正在使用下面的代码获取Jquery UI弹出窗口,但它没有返回值,弹出框正在关闭 我需要当我点击按钮,它必须作为确认框工作 代码: <style type="text/css" > .ui-widget-header, .ui-widget-content { color: red !important;} </style> <script type="text/javascript"> $(document).ready(f
<style type="text/css" >
.ui-widget-header, .ui-widget-content
{ color: red !important;}
</style>
<script type="text/javascript">
$(document).ready(function () {
var $myDialog = $('<div></div>')
.html('You are going to Lock the Record.<br/>Click OK to confirm. Click Cancel to stop this action.')
.dialog({
autoOpen: false,
title: 'Confirm..?',
buttons: { "OK": function () {
$(this).dialog("close");
}, "Cancel": function () {
$(this).dialog("close");
}
}
});
$(function fn() {
$('#Button1').click(function (e) {
return $myDialog.dialog('open');
});
});
});
</script>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return fn() onclick="Button1_Click"/>
<style type="text/css" >
.ui-widget-header, .ui-widget-content
{ color: red !important;}
</style>
<script type="text/javascript">
$(document).ready(function () {
var $myDialog = $('<div></div>')
.html('You are going to Lock the Record.<br/>Click OK to confirm. Click Cancel to stop this action.')
.dialog({
autoOpen: false,
title: 'Confirm..?',
buttons: { "OK": function () {
$(this).dialog("close");
}, "Cancel": function () {
$(this).dialog("close");
}
}
});
$('#Button1').click(function (e) {
$myDialog.dialog('open');
e.preventDefault();
});
});
</script>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click"/>
.ui小部件标题,.ui小部件内容
{颜色:红色!重要;}
$(文档).ready(函数(){
变量$myDialog=$('')
.html('您将锁定记录。
单击“确定”确认。单击“取消”停止此操作。')
.对话({
自动打开:错误,
标题:“确认…”,
按钮:{“确定”:函数(){
$(此).dialog(“关闭”);
},“取消”:函数(){
$(此).dialog(“关闭”);
}
}
});
$(函数fn(){
$('#按钮1')。单击(函数(e){
返回$myDialog.dialog('open');
});
});
});
.dialog(“open”)将始终立即返回,它不会等待用户操作
您需要将代码更改为tigger Button1控件的回发。而不是依赖于返回值
有关触发回发的信息,请参见此处
编辑
<style type="text/css" >
.ui-widget-header, .ui-widget-content
{ color: red !important;}
</style>
<script type="text/javascript">
$(document).ready(function () {
var $myDialog = $('<div></div>')
.html('You are going to Lock the Record.<br/>Click OK to confirm. Click Cancel to stop this action.')
.dialog({
autoOpen: false,
title: 'Confirm..?',
buttons: { "OK": function () {
$(this).dialog("close");
__doPostBack("<%=Button1.ClientID %>","");
}, "Cancel": function () {
$(this).dialog("close");
}
}
});
$(function fn() {
$('#Button1').click(function (e) {
return $myDialog.dialog('open');
});
});
});
</script>
<asp:Button ID="Button1" runat="server" UseSubmitBehavior="false" Text="Button" OnClientClick="return fn()" onclick="Button1_Click"/>
.ui小部件标题,.ui小部件内容
{颜色:红色!重要;}
$(文档).ready(函数(){
变量$myDialog=$('')
.html('您将锁定记录。
单击“确定”确认。单击“取消”停止此操作。')
.对话({
自动打开:错误,
标题:“确认…”,
按钮:{“确定”:函数(){
$(此).dialog(“关闭”);
__doPostBack(“,”);
},“取消”:函数(){
$(此).dialog(“关闭”);
}
}
});
$(函数fn(){
$('#按钮1')。单击(函数(e){
返回$myDialog.dialog('open');
});
});
});
很难理解dom的结构
但我会给你一个有效的解决方案
一些控件或文本或任何您想要显示的内容。/div>//将其添加到页面中。
然后使用Jquery和jQueryUI库,将其放入head标记中
$(function(){
$('#someDialog').dialog({ autoOpen: false,
title: 'Confirm..?',
buttons: { "OK": function () {
if(confirm("are you sure you want to close the dialog))
$(this).dialog("close");
}, "Cancel": function () {
$(this).dialog("close");
});
$('#Button1').click(function (e) {
$('#someDialog').dialog('open');
}); // without return statement.
});
asp.net按钮是否在HTML输出中以ID“Button1”呈现?如果是,您可以尝试以下代码(修改您的代码)
代码:
<style type="text/css" >
.ui-widget-header, .ui-widget-content
{ color: red !important;}
</style>
<script type="text/javascript">
$(document).ready(function () {
var $myDialog = $('<div></div>')
.html('You are going to Lock the Record.<br/>Click OK to confirm. Click Cancel to stop this action.')
.dialog({
autoOpen: false,
title: 'Confirm..?',
buttons: { "OK": function () {
$(this).dialog("close");
}, "Cancel": function () {
$(this).dialog("close");
}
}
});
$(function fn() {
$('#Button1').click(function (e) {
return $myDialog.dialog('open');
});
});
});
</script>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return fn() onclick="Button1_Click"/>
<style type="text/css" >
.ui-widget-header, .ui-widget-content
{ color: red !important;}
</style>
<script type="text/javascript">
$(document).ready(function () {
var $myDialog = $('<div></div>')
.html('You are going to Lock the Record.<br/>Click OK to confirm. Click Cancel to stop this action.')
.dialog({
autoOpen: false,
title: 'Confirm..?',
buttons: { "OK": function () {
$(this).dialog("close");
}, "Cancel": function () {
$(this).dialog("close");
}
}
});
$('#Button1').click(function (e) {
$myDialog.dialog('open');
e.preventDefault();
});
});
</script>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click"/>
.ui小部件标题,.ui小部件内容
{颜色:红色!重要;}
$(文档).ready(函数(){
变量$myDialog=$('')
.html('您将锁定记录。
单击“确定”确认。单击“取消”停止此操作。')
.对话({
自动打开:错误,
标题:“确认…”,
按钮:{“确定”:函数(){
$(此).dialog(“关闭”);
},“取消”:函数(){
$(此).dialog(“关闭”);
}
}
});
$('#按钮1')。单击(函数(e){
$myDialog.dialog('open');
e、 预防默认值();
});
});
你有一个dom就绪的函数在另一个里面。你需要删除上面的块
$(document).ready(function () {
var $myDialog = $('<div></div>')
.html('You are going to Lock the Record.<br/>Click OK to confirm. Click Cancel to stop this action.')
.dialog({
autoOpen: false,
title: 'Confirm..?',
buttons: { "OK": function () {
$(this).dialog("close");
}, "Cancel": function () {
$(this).dialog("close");
}
}
});
$('<%=Button1.ClientID%>').click(function (e) {
$myDialog.dialog('open');
return false;
});
});
$(文档).ready(函数(){
变量$myDialog=$('')
.html('您将锁定记录。
单击“确定”确认。单击“取消”停止此操作。')
.对话({
自动打开:错误,
标题:“确认…”,
按钮:{“确定”:函数(){
$(此).dialog(“关闭”);
},“取消”:函数(){
$(此).dialog(“关闭”);
}
}
});
$('')。单击(函数(e){
$myDialog.dialog('open');
返回false;
});
});
我希望这是对的 将CSS类删除添加到控件,然后应用jquery确认对话框:
$('.delete').click(function () {
return confirm('Are you sure you wish to delete this record?');
});
您错过了OnClientclick=“return fn()”的一个双引号(“),抱歉!它的打字错误,尽管它不起作用,但我已删除。它不起作用。即使我尝试了此操作,但加载时的结果相同。确认正在出现并关闭。我已稍微编辑了代码。$(“#Button1”)。单击
无需返回内容。有关更多详细信息,请参见此。谢谢..我希望它能正常工作..但回发也能正常工作如何在客户端执行相同的功能而不是服务器端?您可以在e.preventDefault();
中添加$(“#Button1”)。在显示对话框后单击
handler。我已经更新了代码,这应该可以防止回发。是/否只是关闭对话框。但是,当我在Jquery UI上单击“是”时,服务器代码必须工作..?我明白你的意思了?你能更清楚地解释我吗?嗨,我已经更新了你的代码,我认为应该工作。我不是在一台pc上,我可以测试它,但很确定它应该能工作。让我知道。Hi Zonder..我正在母版和子版中尝试相同的代码..我得到错误对象预期$(函数fn(){$('#按钮1')。单击(函数(e){return$myDialog.dialog('open');});上面的功能未执行,因为您的按钮正在服务器上运行,它的名称不在按钮位置1用于获取它的真实信息我很抱歉再次返回此处…我没有信誉点聊天我尝试了相同的代码,将样式表和脚本ta放在内容页中,并将其复制到母版页..然后再次出现相同的错误ca我…!我只使用了按钮id,也只使用了按钮1。