一简单点的
如要在一个按钮上增加认证脚本可以这样
<%@ Page Language=C# %>
<SCRIPT language=javascript>
function getconfirm ()
{
if (confirm(Do you want to delete record?)==true)
return true;
else
return false;
}
</SCRIPT>
<script runat=server>
public void Page_Load(Object sender EventArgs E) {
btnSubmitAttributesAdd(onclickreturn getconfirm (););
}
void btnSubmit_Click(object sender EventArgs e) {
MessageText = You entered your name as: + txtNameText;
}
</script>
<html>
<head>
</head>
<body>
<form runat=server>
Name: <asp:Textbox id=txtName runat=server/>
<asp:Button id=btnSubmit onclick=btnSubmit_Click runat=server Text=Submit></asp:Button><br/>
<asp:Label id=Message runat=server/>
</form>
</body>
</html>
注意关键的地方btnSubmitAttributesAdd(onclickreturn fffkkk(););这句话就相当于在静态页面标签上添加 onclick = return fffkkk(); 一样
二 复杂一点的
有的时候我们要在DataGrid的删除列上添加认证可以这样
首先建一个DataGrid然后给她增加一个删除列
<asp:DataGrid id=DataGrid runat=server>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton id=cmdDel
runat=server Text=Delete
CommandName=Delete CausesValidation=false>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
然后在DataGrid 的ItemDataBound事件中这样写
Private Sub DataGrid_ItemDataBound
(ByVal sender As Object ByVal e As DataGridItemEventArgs)
Handles DataGridItemDataBound
Dim l As LinkButton
If eItemItemType = ListItemTypeItem Or
eItemItemType = ListItemTypeAlternatingItem Then
l = CType(eItemCells()FindControl(cmdDel) LinkButton)
lAttributesAdd(onclick return getconfirm();)
End If
End Sub
Getconfirm()函数和第一个是一样的
function getconfirm()
{
if (confirm(Do you want to delete record?)==true)
return true;
else
return false;
}