用户确认消息框如何在ASP.Net中工作
How does user confirmation message box work in ASP.Net
客户端如何知道只有当确认框结果ok时才向服务器发送请求,并且如果取消则留在页面上?另外,这种机制在ASP中有什么不同吗?Net和ASP。净MVC吗?
我得到的回答似乎告诉我如何实现这个功能。我想知道当用户单击OK/取消内部发生的事情的内部工作。浏览器如何知道它必须继续服务器调用或关闭自己什么都不做?
您可以使用简单的confirm
box
$("#callConfirm").on("click", function(e) {
if(confirm('Are you sure'))
alert('Yes');
else
alert('No');
});
JSFIDDLE
Try This
<script>
function CallConfirm()
{
if(confirm('Are you sure'))
//do your stuff
else
return false;
}
<script />
和asp的按钮像这样写
<asp:Button id="Click" runat="server" onclientclick="return CallConfirm();" onclick="btn_Click"/>
你可以在asp.net中使用bootstrap,它将帮助你给你新的外观,并帮助你在许多其他的事情,看看这个http://getbootstrap.com/,你可以使用bootstrap确认框。
<asp:button
id="Button1" runat="server" text="Button" xmlns:asp="#unknown">OnClientClick="return confirmation();" onclick="Button1_Click"/>
</asp:button>
<script type="text/javascript">
function confirmation() {
if (confirm('are you sure you want to delete ?')) {
return true;
}else{
return false;
}
}
</script>
我在aspx页面为按钮编写了这段Jquery代码。
步骤:
-
添加一个按钮,你想有一个确认框,添加它的jquery和div来显示确认框
-
在Page_Load上注册button的脚本,并编写将此脚本绑定到button上的方法
-
也不要忘记按钮点击的服务器端方法或事件,这些将在确认框OK确认后继续。
-
如果取消被点击,什么都不会发生,div将被关闭。
<script type="text/javascript"> function FileItem(callBackFunction, title, content) { $("#File-confirm").html(content).dialog({ autoOpen: true, modal: true, title: title, resizable: false, height: 140, close: function (event, ui) { $(this).dialog("destroy"); }, buttons: { 'Ok': function () { callBackFunction(); $(this).dialog("destroy"); }, 'Cancel': function () { $(this).dialog("destroy"); } }); } }
其中SaveBtn是UI中的按钮:
<asp:Button ID="SaveBtn" runat="server" Text="File" OnClick="SaveBtn_Click"/>
<div id="File-confirm" style="display: none">
</div>
后面的代码:
FileConfirmRequest(SaveBtn, "Confirm", "Are you sure you want to file the changes?");
// In the Page_Load, write the above code
//Use this method later on the page
protected void FileConfirmRequest(Button control, string title, string message)
{
string postBackReference = Page.ClientScript.GetPostBackEventReference(control, String.Empty);
string function = String.Format("javascript:FileItem(function() {{ {0} }}, '{1}', '{2}'); return false;", postBackReference, title, message);
control.Attributes.Add("OnClick", function);
}
现在,按钮的点击:
protected void SaveBtn_Click(object sender, EventArgs e)
{
//Do what you want to after OK Click from the confirm box
}
相关文章:
- 借助asp.net验证或java脚本对多个文本进行验证
- 将Javascript数组发送到控制器ASP.NET MVC
- ASP.NET通过单击JavaScript按钮触发c#事件
- 文本框不是从Javascript/Asp.net中的对话框中打印出来的
- 从javascript调用asp.net codebehind函数
- 使用javascript的Asp.net内容占位符
- 获取ASP.NET Ajax Timer状态
- ASP.NET网络摄像头显示
- 如何在只能有一个asp.net表单的主页上从asp.net页面中的javascript中获取值
- 如何将乳胶配方奶粉图像保存到Asp.net中的文件夹中
- asp.net,包括iss上的javascript slow
- 选择不在GridView-ASP.NET中激发
- 什么'是在asp.net MVC中将本地化的resources.resx文件转换为javascript文件的有效
- 使用ASP.NET将谷歌地图添加到项目中,并从数据库中检索位置
- 有什么“;错误的”;将javascript放在asp.net表单上,而不是放在单独的文件中
- 将Javascript日期转换为ASP.NET日期格式
- C#asp.net mvc Set CheckBoxFor已检查的具有Model Value的属性
- 在asp.net中确认是或否消息
- ASP.NET MVC 3-在ajax调用后,重定向到新页面或生成页面刷新
- asp.net中的验证工具