|
1) Simple
To add an authentication script to a button, you can
<% @ 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>
<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>
Note the key points btnsubmit. attributes. add ("onclick", "Return fffkkk ();"); this statement is equivalent to adding "onclick =" Return fffkkk (); "to the static page tag.
2) more complex
Sometimes we need to add authentication in the delete column of the DataGrid.
First, create a DataGrid and add a delete column to her.
<Asp: DataGrid id = "datagrid1" runat = "server">
<Columns>
<Asp: templatecolumn>
<Itemtemplate>
<Asp: linkbutton id = "mongodel"
Runat = "server" text = "delete"
Commandname = "delete" causesvalidation = "false">
</ASP: linkbutton>
</Itemtemplate>
</ASP: templatecolumn>
</Columns>
</ASP: DataGrid>
Then write in the itemdatabound event of the DataGrid 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 ("mongodel"), 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;
}
In this way, I have summarized the above information in the compilation process and may be useful to you. |