• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 115
  • Last Modified:

Messagebox for a Web Site Application

Hello,
I am converting a Windows Form application to a Web Site Application.  I am trying to convert my CreateEmail class.  Everything crosses over fine except for the message box.

I need the equivalent for this statement for this application.

System.Windows.Forms.MessageBox.Show("There is no such record in your address book.")

Here is all the code I am using in the class.

Imports Microsoft.VisualBasic
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports System.Runtime.InteropServices
Imports System.Web.UI

Public Class CreateEmail
    Public emailPickList As New List(Of String)
    Public emailCCList As New List(Of String)
    Public emailSubject As String = ""
    Public emailBody As String = ""

    Public Sub GenerateEmail()

        Dim OutlookApp As New Outlook.Application
        OutlookApp = CreateObject("Outlook.Application")

        Dim mail As Outlook.MailItem = Nothing
        Dim mailRecipients As Outlook.Recipients = Nothing
        Dim mailRecipient As Outlook.Recipient = Nothing

        Try
            mail = OutlookApp.CreateItem(Outlook.OlItemType.olMailItem)
            mail.Subject = emailSubject
            mailRecipients = mail.Recipients

            For Each x In emailPickList
                Dim rcpt As String = x
                mailRecipient = mailRecipients.Add(rcpt)
                mailRecipient.Type = Outlook.OlMailRecipientType.olTo
            Next


            'CC receiptients
            If emailCCList.Count > 0 Then
                For Each x In emailCCList
                    Dim rcpt As String = x
                    mailRecipient = mailRecipients.Add(rcpt)
                    mailRecipient.Type = Outlook.OlMailRecipientType.olCC
                Next
            End If

            With mail
                .Body = emailBody
            End With

            mailRecipient.Resolve()
            If (mailRecipient.Resolved) Then
                mail.Send()
            Else
               'System.Windows.Forms.MessageBox.Show("There is no such record in your address book.")
           End If
        Catch ex As Exception
            'System.Windows.Forms.MessageBox.Show(ex.Message, "An exception is occured in the code of add-in.")
       Finally
            If Not IsNothing(mailRecipient) Then Marshal.ReleaseComObject(mailRecipient)
            If Not IsNothing(mailRecipients) Then Marshal.ReleaseComObject(mailRecipients)
            If Not IsNothing(mail) Then Marshal.ReleaseComObject(mail)
        End Try

    End Sub
EndClass

Any assistance would be appreciated.
Karen
0
Karen Wilson
Asked:
Karen Wilson
  • 2
  • 2
1 Solution
 
Shaun KlineLead Software EngineerCommented:
There is no exact equivalent of the MessageBox on the Web. There are ways to simulate it using JavaScript's alert command, or writing the message out to the calling page. The challenge you will need to handle is how to return your message from your class to the calling page, as you cannot raise JavaScript alerts or write directly to the calling page from a class.

One was to pass the message back is to change your sub to a function and return a Boolean/int/string to indicate whether the function processed correctly or not. If it did not process correctly, you could set a property of the class to contain the "error" message.
0
 
Karen WilsonAuthor Commented:
Thanks Shaun for responding.  I kept thinking - I am going to have to go outside of this code to create a message box.  I am on the right track then???  

I saw the alert command in different code as I was researching my problem.  Do you have a good link for me to learn how to do this?  I'm very new to the javascript.
0
 
Shaun KlineLead Software EngineerCommented:
To cause a JavaScript alert to run when a page posts back you would need to "write" a script block to you page.

ASP.Net WebForms does this for you using the RegisterStartupScript method, as seen here: https://msdn.microsoft.com/en-us/library/asz8zsxy(v=vs.110).aspx

If you are using ASP.Net MVC, you can reference this link for creating the alert message: http://www.aspdotnet-pools.com/2014/06/display-alert-message-on-page-load-in.html
0
 
Karen WilsonAuthor Commented:
Thanks for the links.  I was on the one page so at least I was in the right direction.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now