locked
Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. RRS feed

  • Question

  •   

    Hi,

    I am writing a web application using .net 3.5 and vs 2008 which allows people to add data to a db via a control panel front end.

    Objective: Before committing one of the fields to the db i would like the user to answer Yes, No or Cancel to confirm their action.

    I have tried to implement this with a modal dialog box  or message box but the following error appears:


    Server Error in '/' 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:

     

    Line 174:

    Line 175:            'Exit Sub

    Line 176:            If Not modDB.doContinue("Save " & txtEvnName.Text & " as New Event?") Then

    Line 177:                modDB.blankControls(divEvn.Controls) 'blank controls

    Line 178:                'PopulateEve()


    Source File: C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\FuseV2\Fusev2\root\ccp\eventmanagement.aspx.vb    Line: 176

    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) +1799842

       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

       Fusev2.modDB.doContinue(String prompt, Object& obj) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\FuseV2\Fusev2\mods\modDB.vb:589

       Fusev2.EventManagement.btnAddEvn_Click(Object sender, EventArgs e) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\FuseV2\Fusev2\root\ccp\eventmanagement.aspx.vb:176

       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) +1746

     


    Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433


    ----
     

    I would then like to carry on with the code behind the aspx and process the answer and its corresponding actions.

     

     

    The function which is causing this error is:

     

        Public Function doContinue(ByVal prompt As String, Optional ByRef obj As Object = Nothing) As Boolean

            If Not obj Is Nothing Then

                cantSeeMee(obj)

            End If

            doContinue = CBool(MsgBox(prompt, MsgBoxStyle.YesNo, "") = MsgBoxResult.Yes)

        End Function

     

    Now I don’t think you will need the cantSeeMee(Object) Function because obj is null, hence cantSeeMee() is never called.

     

    I would like support on the following:

    1 - Can message boxes be used in asp.net 3.5 to achieve my above objective? And if yes how?

    2 - If not what are my alternatives?

    Language used: VB.net

    Thanks to everyone who responds.

    • Moved by Laura Petersen Friday, September 5, 2008 9:37 PM better forum to answer question (Moved from Visual Studio Debugger to Visual Basic General)
    Friday, September 5, 2008 5:27 PM

Answers

  • Hello!

    in Web Applications, when you create a Modal Dialog Box using MsgBox or MessageBox, even it would of been shown, it would of been shown in your server, not on the clients computer.

    I suggest you to use an ajax:ConfirmButton or ajax:ModalPopup or another Ajax Control spread over the web.


    however, it is certainly impossible to Show a Windws based Modal Box on the client using MsgBox or MessageBox etc.

    BTW, these questions might have a quiker answer in ASP.NET forums.

    hope this was helpful, Shimmy.


    Shimmy
    Monday, September 8, 2008 7:40 AM

All replies

  • Hello!

    in Web Applications, when you create a Modal Dialog Box using MsgBox or MessageBox, even it would of been shown, it would of been shown in your server, not on the clients computer.

    I suggest you to use an ajax:ConfirmButton or ajax:ModalPopup or another Ajax Control spread over the web.


    however, it is certainly impossible to Show a Windws based Modal Box on the client using MsgBox or MessageBox etc.

    BTW, these questions might have a quiker answer in ASP.NET forums.

    hope this was helpful, Shimmy.


    Shimmy
    Monday, September 8, 2008 7:40 AM
  • Take a look at MessageBoxOptions Enumeration.  You can specify ServiceNotification, or DefaultDesktopOnly options, for when you have no form.

    Here is an example.

     

            MessageBox.Show("Message", "Caption", MessageBoxButtons.OK, _

            MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, _

            MessageBoxOptions.ServiceNotification)

     

    • Proposed as answer by Clausss Friday, April 15, 2011 6:15 PM
    Monday, September 8, 2008 8:52 AM
  • I wish I would of had this functionality in web :-(
    you can develop one if you're looking for chalenges and you have free time...

    you can even override the existing ConfirmButton as it's open source.

    anyway, if you did or you find such a control, please post a link here so we can all enjoy it

    thank you!
    Shimmy
    Monday, September 8, 2008 9:00 AM
  • Why not just do the confirmation on the clientside using javascript before you postback to write the data to the db? or am i missing something?
    Thanks..
    Monday, April 19, 2010 2:37 AM
  • Good idea, but is harder to control from server on special server event, or if you want to get the dialog result, or when you want to display dynamic data.

    The Ajax tools allow all this easily with no getting the hands dirty with js.


    Shimmy
    Monday, April 19, 2010 3:34 AM
  • Thanx......I am facing the same problem,, problem get solved........
    Wednesday, September 29, 2010 11:11 AM
  • this code is not working when we put our web page put on server.
    Wednesday, October 6, 2010 11:19 AM
  • I am having the same problem with a popup message box not displaying from a server.  Did anyone find a solution to this problem?

    Thanks

    Tuesday, February 15, 2011 8:51 PM
  • Use this function

    Public

    Sub ShowMessage(ByVal MessageText As String, ByVal MyPage As Page)

    MyPage.ClientScript.RegisterStartupScript(MyPage.GetType(), _

     

    "MessageBox", "alert('" & MessageText.Replace("'", "\'") & "');", True)

     

     

    End Sub
     
    • Proposed as answer by casilvis Thursday, August 1, 2013 8:12 PM
    Thursday, March 31, 2011 10:01 AM
  • M sirvio mucho para mi windows service :D

    • Proposed as answer by saracenop Friday, December 5, 2014 12:42 PM
    Friday, April 15, 2011 6:15 PM