Saturday, December 06, 2003

When writing an ASP.NET it may come in handy to pop up an alert box. For example, I was completing some code for a customer that was doing a login dialog. One of the requirements was to show an alert dialog when the login failed. This is pretty easy using the following code within an ASP.NET page.

Private Sub btnLoginAccount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoginAccount.Click

Dim ws As New localhost.SweetsService
Dim ValidUser As Boolean
ValidUser = ws.ValidateUser(EmailID:=TxtUsername.Text, Password:=TxtPassword.Text)

If ValidUser = True Then
CurrentUserEmail = TxtUsername.Text
FormsAuthentication.SetAuthCookie(username:=TxtUsername.Text, createPersistentcookie:=
False)
Else
Response.Write("<script>alert('Invalid username/password')</script>")
End If

TxtUsername.Text = ""
TxtPassword.Text = ""
End Sub


10:08:27 PM    

Wanted to send email from .NET? Well here is a quick class that you can use to send email with.

Imports System.Web.Mail
Public Class SendMail
Public Function SendPurchaseMessage(ByVal EmailAddress As String)
Dim Message As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage

Message.To = "Who the email is going to"
Message.From = "Who the email is coming from"
Message.Subject = "Message Subject"
Message.Body = "Body of the message"
SmtpMail.SmtpServer = "Enter your SMTP server"
SmtpMail.Send(Message)

End Function
End
Class


5:20:55 PM