Solved

MSGBOX IN ASP.NET using Visual Studio Express

Posted on 2006-06-19
8
4,781 Views
Last Modified: 2009-12-29
How is it that I can see the msgbox popup when I view the webpage in the browser in VW but when I try to view it in IIS I get this error when I try to view the messagebox:

Server Error in '/INVENTORY' Application.
--------------------------------------------------------------------------------

Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
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: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

  <%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.  

Stack Trace:


[InvalidOperationException: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.]
   System.Windows.Forms.MessageBox.ShowCore(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, Boolean showHelp) +1801522
   System.Windows.Forms.MessageBox.Show(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options) +26
   Microsoft.VisualBasic.Interaction.MsgBox(Object Prompt, MsgBoxStyle Buttons, Object Title) +544
   _Default.Button2_Click(Object sender, EventArgs e) +85
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
0
Comment
Question by:JWFreedom
  • 4
  • 4
8 Comments
 
LVL 16

Expert Comment

by:OliWarner
ID: 16936747
You cannot use System.Windows.Forms.MessageBox in an aspnet app...
Windows.Forms are for WinForms... needless to say... I'll get back with some real code in a second..
0
 
LVL 16

Accepted Solution

by:
OliWarner earned 500 total points
ID: 16936778
Infact take your pick...
http://www.google.co.uk/search?q=messagebox+in+aspnet

Personally, I would go with ~#4... the Code Project one.


A messagebox in html is javascript, not a Windows Form.
0
 

Author Comment

by:JWFreedom
ID: 16936971
All I have is a simple little code that when a user presses a button twice, a msgbox comes up stating that the view is already in view.  So iwouldn't know even where to begin placing all thee syntax that those pages refered to.  Here is an example of my VB code for my page:

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim msg As String
        Dim title As String
        Dim style As MsgBoxStyle
        msg = "Grid Already in View" ' Define message.
        style = MsgBoxStyle.ApplicationModal
        title = "Already in View" ' Define title.


        DetailsView1.Visible = False
        Label1.Visible = False

        If GridView1.Visible Then
            MsgBox(msg, style, title)
        Else
        If GridView1.Visible = False Then
            GridView1.Visible = True

        End If
        If Label2.Visible = False Then
            Label2.Visible = True
        End If
        End If


    End Sub
    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        GridView1.Visible = False
        Label2.Visible = False

        If DetailsView1.Visible Then
            MsgBox("Detail is already in view")
        Else
            If DetailsView1.Visible = False Then
                DetailsView1.Visible = True
            End If
            If Label1.Visible = False Then
                Label1.Visible = True
            End If
        End If


    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
End Class
0
 
LVL 16

Expert Comment

by:OliWarner
ID: 16937068
You cannot do this logic in aspnet... this is all client side stuff.

If you want to do this as you're trying, you need to postback and display the error on the page. Otherwise you need to learn how this all ties together, and fit some JS in there.

I would go with the first option.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:JWFreedom
ID: 16937112
The error on the page is the first entry I submitted.  Im not sure where to begin when applying JS,  is in the Source view or the VB view
0
 
LVL 16

Expert Comment

by:OliWarner
ID: 16937217
Its a tough call...

You'll need a boolean in javascript = false... When you load the thing you dont want loading twice, you're going to need to set that to true then check (in js when its next clicked) if its true or false...

You're going to need a mix of inline (to add an onclick to the button) and your main JS in the source view.


Or you handle it through postback and its all (hopefully) a lot easier
0
 

Author Comment

by:JWFreedom
ID: 16937284
FYI;;

I thank you for your geniousity.  I figured it out, Thanks to your help;; here is the code:


Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        DetailsView1.Visible = False
        Label1.Visible = False

        If GridView1.Visible Then
            MessageBox.Show("Grid is Already in View")
        Else
            If GridView1.Visible = False Then
                GridView1.Visible = True

            End If
            If Label2.Visible = False Then
                Label2.Visible = True
            End If
        End If


    End Sub
    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        GridView1.Visible = False
        Label2.Visible = False

        If DetailsView1.Visible Then
            MessageBox.Show("Detail is Already in View")
        Else
            If DetailsView1.Visible = False Then
                DetailsView1.Visible = True
            End If
            If Label1.Visible = False Then
                Label1.Visible = True
            End If
        End If


    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
End Class
Public Class MessageBox
    Private Shared m_executingPages As New Hashtable()


    Private Sub New()
    End Sub 'New

    Public Shared Sub Show(ByVal sMessage As String)
        ' If this is the first time a page has called this method then
        If Not m_executingPages.Contains(HttpContext.Current.Handler) Then
            ' Attempt to cast HttpHandler as a Page.
            Dim executingPage As Page = HttpContext.Current.Handler '
            'ToDo: Error processing original source shown below
            '
            '
            '--------------------------------------------------------^--- Syntax error: ';' expected

            If Not (executingPage Is Nothing) Then
                ' Create a Queue to hold one or more messages.
                Dim messageQueue As New Queue()

                ' Add our message to the Queue
                messageQueue.Enqueue(sMessage)

                ' Add our message queue to the hash table. Use our page reference
                ' (IHttpHandler) as the key.
                m_executingPages.Add(HttpContext.Current.Handler, messageQueue)

                ' Wire up Unload event so that we can inject
                ' some JavaScript for the alerts.
                AddHandler executingPage.Unload, AddressOf ExecutingPage_Unload
            End If
        Else
            ' If were here then the method has allready been
            ' called from the executing Page.
            ' We have allready created a message queue and stored a
            ' reference to it in our hastable.
            Dim queue As Queue = CType(m_executingPages(HttpContext.Current.Handler), Queue)

            ' Add our message to the Queue
            queue.Enqueue(sMessage)
        End If
    End Sub 'Show

    ' Our page has finished rendering so lets output the
    ' JavaScript to produce the alert's
    Private Shared Sub ExecutingPage_Unload(ByVal sender As Object, ByVal e As EventArgs)
        ' Get our message queue from the hashtable
        Dim queue As Queue = CType(m_executingPages(HttpContext.Current.Handler), Queue)

        If Not (queue Is Nothing) Then
            Dim sb As New StringBuilder()

            ' How many messages have been registered?
            Dim iMsgCount As Integer = queue.Count

            ' Use StringBuilder to build up our client side JavaScript.
            sb.Append("<script language='javascript'>")

            ' Loop round registered messages
            Dim sMsg As String
            While (iMsgCount > 0)
                iMsgCount = iMsgCount - 1
                sMsg = CStr(queue.Dequeue())
                sMsg = sMsg.Replace(ControlChars.Lf, "\n")
                sMsg = sMsg.Replace("""", "'")
                sb.Append("alert( """ + sMsg + """ );")
            End While
            ' Close our JS
            sb.Append("</script>")

            ' Were done, so remove our page reference from the hashtable
            m_executingPages.Remove(HttpContext.Current.Handler)

            ' Write the JavaScript to the end of the response stream.
            HttpContext.Current.Response.Write(sb.ToString())
        End If
    End Sub 'ExecutingPage_Unload

End Class 'MessageBox
0
 

Author Comment

by:JWFreedom
ID: 16937300
ANother question,, if you would ,how can I send a ucase to the sql database through ASP.net
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

757 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

22 Experts available now in Live!

Get 1:1 Help Now