Archive for July, 2008|Monthly archive page

Javascript alert box and confirmation box in ASP.NET

In HTML, the code will be:

<input type="submit" name="ButtonNote" value="Note" id="ButtonNote"
onclick="alert('Alert message appears in here.');" />

<input type="submit" name="ButtonDelete" value="Delete" id="ButtonDelete"
onclick="return confirm('Are you sure you want to delete?');" />

In ASP.NET, the VB code to accomplish the same thing will be:

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
   If (Not Page.IsPostBack) Then
      Me.ButtonNote.Attributes.Add("onclick", _
      "alert('Alert message appears in here.');")
      Me.ButtonDelete.Attributes.Add("onclick", _
      "return confirm('Are you sure you want to delete?');")
   End If
End Sub