Ok, i am facing this error on red line
Code:
Asynchronous operations are not allowed in this context. Page starting an asynchronous operation has to have the Async attribute set to true and an asynchronous operation can only be started on a page prior to PreRenderComplete event.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Asynchronous operations are not allowed in this context. Page starting an asynchronous operation has to have the Async attribute set to true and an asynchronous operation can only be started on a page prior to PreRenderComplete event.
My code
Code:
Public Shared Function SendMailUpdate(ByVal emails As String)
Dim SmtpMail As New System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings("SmtpServer"), 25)
Dim myMail As New MailMessage()
'SmtpMail.DeliveryMethod = SmtpDeliveryMethod.Network
Dim arr_email_to As Array = Split(emails, ";")
For Each email_to As String In arr_email_to
myMail.To.Add(New MailAddress(email_to))
Next
myMail.From = New MailAddress(ConfigurationManager.AppSettings("NoReply"))
myMail.Body = ""
myMail.Subject = "Update"
Dim mailBox As Object = myMail
AddHandler SmtpMail.SendCompleted, AddressOf SmtpClient_OnCompleted
SmtpMail.SendAsync(myMail, mailBox)
End Function
Function is called from a page like this
Code:
GlobalClasses.SendMailUpdate(strEmailIDs)
Any ideas?
Bookmarks