Today I learned about option for LinkButton "onclientclick" This option gives me a chance to execute a javascript function directly from asp.net page. Here's an example
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete" onclientclick="return confirm('Are you sure you want to delete?');" />
We can reach the same effect using code-behind:
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If (Not Page.IsPostBack) Then
Me.DeleteButton.Attributes.Add("onclick", _
"return confirm('Are you sure you want to delete?');")
End If
End Sub
It's quite interesting how asp-net works with javascript
No comments:
Post a Comment