你所说“i have tried it,but the server event is still triggered,help! ”如果不想服务器端有事件响应你可以直接使用 html控件
i think the question lie you lay the code on wrong place, you can follow the sample: private void Page_Load(object sender, System.EventArgs e) { //your client trigger if(!Page.IsPostBack) { btn1.Attributes.Add("onclick","return confirm('确定吗?');"); } } private void btAdd_Click(object sender, System.EventArgs e) { //your server code } remember confirm() writting in the client!
例如Button.Attributes.Add("OnClick","alert('sdfsfsff')")
可是当执行client 的javascript后,the button server event is also triggered,why?
“是”继续执行server事件,“否”就不执行了。
在代码中(如:page_load中)写入:
你的按钮.Attributes["onclick"] = "javascript:alert("error");";
上面说的都是对的呀,你怎么还不明白呢?
Btn.Attributes["onclick"] = "javascript:someAction();"; 这段代码是写在服务端,
然后在客户端写someAction(); 则点击按钮的时候先触发 客户端someAction()然后在响 应服务端事件
你所说“i have tried it,but the server event is still triggered,help!
”如果不想服务器端有事件响应你可以直接使用 html控件
you can follow the sample:
private void Page_Load(object sender, System.EventArgs e)
{
//your client trigger
if(!Page.IsPostBack)
{
btn1.Attributes.Add("onclick","return confirm('确定吗?');");
}
}
private void btAdd_Click(object sender, System.EventArgs e)
{
//your server code
}
remember confirm() writting in the client!