我有一个JS方法,如下所示:(我不知道它是否100%正确)
<script Type="Text/Javascript">
if (confirm("Are you SUre ?")) {
return true;
} else {
return false;
}
</script>并有一些疑问:
首先:我有一个名为JS的文件夹,我打算把它放在那里,对吗?
第二:我将在Edit页面上使用它,所以当customer clickon the button edit时,我希望通过像"Are you Sure?和按钮Yes/No这样的消息来确认。如果customer clicks on the Yes,那么我将继续使用我的edit on database。那么我该怎么做呢?当客户点击ImageButton时,我该如何调用这个方法?
还有一件事:如何获得此方法的返回并使用C#在我的aspx.cs上使用它?
我尝试了下面的代码,但不起作用=\它显示了popUp,但即使我单击cancel,它也会转到OnClick方法
<asp:ImageButton ID="Btn_Alterar" runat="server" ImageUrl="~/Imgs/btAlterar.jpg" OnClick="Btn_Alterar_Click" OnClientClick="confirm()" />发布于 2013-01-22 21:28:20
这应该是可行的。它将弹出一个问题,如果他们说是,那么将处理服务器端代码(作为示例)。
JS:
<script language="javascript">
<!--
function doConfirm() {
if (confirm("Are you SUre ?")) {
//Person has said Yes, do your thing. Next line will allow the server side code to be processed
return true
} else {
//User said No, do nothing and leave next line so the function call exits.
return false
}
}
-->
</script>ASP.NET控件:
<asp:ImageButton id="bMyButton" runat="server" onClientClick="doConfirm()" OnClick="DoServerSideCode" />.CS
protected void DoServerSideCode(object sender, EventArgs e)
{
//This will be called if JS is disabled OR the user clicks Yes. If the user clicks No then this won't be called. You can do DB logix here.
}编辑:(感谢@justnS)
另一种实现方式是:
ASP.NET控件:
<asp:ImageButton id="bMyButton" runat="server" onClientClick="return confirm('Are you sure?')" OnClick="DoServerSideCode" />上面的实现与前面的实现完全相同,但需要的代码更少,而且是内联完成的。
发布于 2013-01-22 21:55:48
$(‘#mylink’).click(.click(E){ e.preventDefault();//有删除数据库中内容的操作吗?转到这里..}
当然,你需要jQuery..
https://stackoverflow.com/questions/14459548
复制相似问题