更新时间:2023-02-07 12:22:31
Button btn = new Button();
btn.Text = "Delete";
btn.Attributes["onclick"] = "javascript: if( confirm(''Do you want to delete?'') ) { delete(); } return false;";
Controls.Add(btn);
与Mark相似,但是我通常这样做会触发删除"服务器的功能.
因此,通过修改他的JavaScript即可:
similar to Mark''s, but what I usually do it fire the "delete" functionality from the server.
Therefore, by modifying his JavaScript a smidge:
btn.Attributes["onclick"] = "javascript: return confirm(''Do you want to delete?'');";
通过将确认(其结果为真/假值)直接传递给onclick处理程序,如果返回cancel/false属性,则onclick不会完成,并且表单提交不会发生.
By passing the confirm (which gives a true/false value as a result) directly to the onclick handler, if you return a cancel/false attribute, the onclick doesn''t complete and the form submittal will not occur.