onsubmit.aspx
来自「C#开发者可使用的经典案例集,源自于ASP.NET经典范例50讲」· ASPX 代码 · 共 52 行
ASPX
52 行
<html>
<head>
<title>Submit脚本</title>
<script language="javascript">
function OnSubmit()
{
window.event.returnValue = confirm("您确定要删除选定的项目?");
}
</script>
<script language="C#" runat="server">
void Page_Load()
{
if(!IsPostBack)
{
ArrayList employees = new ArrayList();
employees.Add("Amazon");
employees.Add("Barbarian");
employees.Add("Wizard");
employees.Add("Knight");
employees.Add("Ghost");
CheckBoxList1.DataSource = employees;
CheckBoxList1.DataBind();
Button1.Attributes.Add("onclick", "OnSubmit()");
}
}
void OnDelete(object sender, EventArgs arg)
{
for( int i=0; i<CheckBoxList1.Items.Count; i++)
{
ListItem item = CheckBoxList1.Items[i];
if(item.Selected)
{
CheckBoxList1.Items.Remove(item);
i--;
}
}
}
</script>
</head>
<body>
<h3>Submit脚本</h3>
<form id="form1" runat="server">
<asp:CheckBoxList id="CheckBoxList1" runat="server" />
<hr/>
<asp:Button id="Button1" Text="删除" OnClick="OnDelete" runat="server" />
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?