# Msg box and .net 3.5



## rg2008 (Sep 5, 2008)

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.


----------



## shahul99 (Aug 27, 2008)

even i had the same problem. though it worked perfectly on my local machine , i had the same error you got after deploying it in the hosting server. 

anyways, you can use javascript to display message.


----------

