Solved

Messagebox for a Web Site Application

Posted on 2016-08-04
4
60 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
  • 2
  • 2
4 Comments
 
LVL 25

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 25

Accepted Solution

by:
Shaun Kline earned 500 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now