?
Solved

Messagebox for a Web Site Application

Posted on 2016-08-04
4
Medium Priority
?
101 Views
Last Modified: 2016-08-04
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
Comment
Question by:Karen Wilson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 26

Expert Comment

by:Shaun Kline
ID: 41743206
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
 

Author Comment

by:Karen Wilson
ID: 41743212
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
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 2000 total points
ID: 41743225
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
 

Author Closing Comment

by:Karen Wilson
ID: 41743232
Thanks for the links.  I was on the one page so at least I was in the right direction.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question