如何在没有回发的情况下确认js? [英] How I can make js confirmation without postback?

查看:87
本文介绍了如何在没有回发的情况下确认js?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。当我点击按钮时,我有asp.net页面和确认消息。但是当我点击是时我的页面刷新(做回发)。如何在不重新刷新页面的情况下发出确认消息?

Asp.net C#Framework 2.0 JS

Hi everyone. I have asp.net page and confirmation message when I click on button. But when i click yes to this my page refreshing( do postback). How can I make confirmation message without resfreshing my page?
Asp.net C# Framework 2.0 JS

<asp:Button ID="SaveBtn" runat="server"  Text="Save" CssClass="btngo" OnClientClick="javascript:return confirm('Do you want to Save?');" OnClick="SaveBtn_Click" />

推荐答案

当你点击一个附加了服务器端事件的按钮(在你的情况下是SaveBtn_Click)时,页面会自动回发...

确认已经与它无关,唯一的连接是客户端甚至处理程序在服务器端调用BEFORE,并且如果返回false则可以停止回发...

所以,如果选择否/取消在你的确认对话框中,它将返回false并且进程将不会继续 - 没有回发。

但是如果你选择是/ OK,确认对话框将返回true并且服务器端事件处理程序将被调用 - postback!
When you hit a button that has as server side event attached to it (in your case SaveBtn_Click) the page will do a postback automatically...
The confirmation has nothing to do with it, the only connection is that the client side even handler called BEFORE the server side one, and can stop postback if it returns false...
So, if you choose No/Cancel in your confirmation dialog, it will return false and the process will not continue - no postback.
However if you choose Yes/OK the confirmation dialog will return true and the server side event handler will be called - postback!


当用户在js确认框中单击是时,您可以对服务器端方法进行ajax调用。参考: AJAX for Beginners(第3部分) - 呼叫服务器ASP.NET网站上的JavaScript方法和消费Web服务 [ ^ ]这样就不会有页面刷新。
You can make an ajax call to the server side method when the user click yes in the js confirm box. Refer: AJAX for Beginners (Part 3) - Calling Server Side Methods and Consuming Web Services from JavaScript in an ASP.NET website[^] so that there will be no page refresh.


最简单的方法是放您在asp:UpdatePanel内的控件。这将以异步方式提交表单,无需刷新页面,您无需进行任何编码。
The simplest way is to put your controls inside an asp:UpdatePanel. That will submit the form asynchronously with no page refresh and you don't need to do any coding.


这篇关于如何在没有回发的情况下确认js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆