A simple point of
To add an authentication script to a button, you can
Copy Code code as follows:
<%@ 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) {
BTNSUBMIT.ATTRIBUTES.ADD ("onclick", "return Getconfirm ();");
}
void btnSubmit_Click (object sender, EventArgs e) {
Message.Text = "You entered your name as:" + txtname.text;
}
</script>
<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>
Attention to key places BtnSubmit.Attributes.Add ("onclick", "return Fffkkk ();"); This sentence is equivalent to adding "onclick =" return Fffkkk () on the tab of static pages.
II) a bit more complicated
Sometimes we have to add authentication on the Delete column of the DataGrid, so you can
First build a DataGrid and then add a delete column to her
Copy Code code as follows:
<asp:datagrid id= "DATAGRID1" 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>
And then write that in the ItemDataBound event in the DataGrid.
Copy Code code as follows:
Private Sub Datagrid1_itemdatabound
(ByVal sender as Object, ByVal e as DataGridItemEventArgs)
Handles Datagrid1.itemdatabound
Dim L as LinkButton
If E.item.itemtype = ListItemType.Item Or
E.item.itemtype = ListItemType.AlternatingItem Then
L = CType (e.item.cells (0). FindControl ("Cmddel"), LinkButton)
L.attributes.add ("onclick", "return Getconfirm ();")
End If
End Sub
The Getconfirm () function is the same as the first one.
function Getconfirm ()
{
if (Confirm ("Do you want to delete record?") ==true)
return true;
Else
return false;
}