asp:button按下弹出javascript确认窗口

weeksun23 2011-05-21 12:20:37
我想实现这样一个效果:
当asp:button按下后,弹出javascript确认窗口,当选择是时,就继续执行asp:button click的剩余代码(有更新数据库操作)否则就不执行,这样应该如何编写代码呢??(实现语言为C#)
...全文
124 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
weeksun23 2011-05-21
  • 打赏
  • 举报
回复
ding
遥望那些年 2011-05-21
  • 打赏
  • 举报
回复

<script language="javascript" type="text/javascript">
function check()
{
if(confirm("确认此操作?"))
return true;
else
return false;
}
</script>
<asp:Button ID="Save" runat="server" Text="保存" OnClick="Save_Click" OnClientClick="return check()" />


#blackheart 2011-05-21
  • 打赏
  • 举报
回复
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick="return confirm('提示信息');" onclick="Button1_Click" />
threenewbee 2011-05-21
  • 打赏
  • 举报
回复
ClientScript.RegisterClientScriptBlock(this.GetType(), "key", "<script type='text/javascript'>if(confirm('继续?'))location='default.aspx?confirm=true'</script>");

=>

ClientScript.RegisterClientScriptBlock(this.GetType(), "key", "<script type='text/javascript'>if(confirm('继续?'))location='default.aspx?confirm=true;else location='default.aspx?confirm=false;'</script>");
weeksun23 2011-05-21
  • 打赏
  • 举报
回复
是否应改为
if (curr == 1)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "key", "<script type='text/javascript'>alert('你选择了继 续');location='default.aspx';</script>");
return;
}

不然的话 不断刷新页面 会弹出‘你选择了继续’窗口
threenewbee 2011-05-21
  • 打赏
  • 举报
回复
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

</asp:Content>
threenewbee 2011-05-21
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
private int curr = 0;

protected void Page_Load(object sender, EventArgs e)
{
string s = "";
try
{ s = this.Request.QueryString["confirm"]; }
catch
{ }
if (s == "true")
{ curr = 1; Button1_Click(this, new EventArgs()); }
else
{ curr = 0; }
}

protected void Button1_Click(object sender, EventArgs e)
{
if (curr == 0)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "key", "<script type='text/javascript'>if(confirm('继续?'))location='default.aspx?confirm=true'</script>");
return;
}
if (curr == 1)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "key", "<script type='text/javascript'>alert('你选择了继续')</script>");
return;
}
}
}
}
遥望那些年 2011-05-21
  • 打赏
  • 举报
回复
<script>
function conf()
{
if(confirm("are you sure?"))
return true;
else
return false;
}
</script>

<asp:button onclick="return conf();" />

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧