关于一个onclientclick的问题
我点击第一个imagebutton不管点击是或否后台都显示
而点击第二个imagebutton点击是才显示后台
或说这是为什么呢,求指教啊。。。
分不多。。。
[code=HTML][/code]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function ShowInfo()
{
return confirm('要执行后台吗?');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ImageButton ID="ImageButton1" runat="server" Height="99px" OnClientClick="ShowInfo()"
OnClick="ImageButton1_Click" Width="75px" />
<asp:ImageButton ID="ImageButton2" runat="server" OnClick="ImageButton1_Click" Width="88px" OnClientClick="return confirm('要执行后台吗?');"/></div>
</form>
</body>
</html>
[code=C#][/code]
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Page.ClientScript.RegisterStartupScript(this.GetType(),"","<script>alert('后台显示')</script>");
}
}
------解决方案--------------------<asp:ImageButton ID="ImageButton1" runat="server" Height="99px" OnClientClick="return ShowInfo()"
OnClick="ImageButton1_Click" Width="75px" />
------解决方案--------------------<asp:ImageButton ID="ImageButton1" runat="server" Height="99px" OnClientClick="if(!ShowInfo()){return false;}"
OnClick="ImageButton1_Click" Width="75px" />