我在一个radiobutton上加上一个javascript的onclick事件,比如alert一句话,运行没有问题。
但当我radiobutton设置为autopostback,并且触发一个服务器端的checkchanged事件后,刚才加的onclick事件就无法执行了,可能是被这个服务器端事件覆盖了。比如说我想点击这个radiobutton时,先alert出一句话,紧接着执行服务器端事件,有没有办法?
但当我radiobutton设置为autopostback,并且触发一个服务器端的checkchanged事件后,刚才加的onclick事件就无法执行了,可能是被这个服务器端事件覆盖了。比如说我想点击这个radiobutton时,先alert出一句话,紧接着执行服务器端事件,有没有办法?
{
RadioButton1.Attributes.Add("onclick", "alert('aaa');");
RadioButton2.Attributes.Add("onclick", "alert('bbb');");
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButton ID="RadioButton1" runat="server"
oncheckedchanged="RadioButton1_CheckedChanged" AutoPostBack="true" onclick="alert('fd');"/>
</div>
</form>
</body>
</html>Default.aspx.cs:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
Response.Write("sss");
}
}