Help with an IIS page and Default.aspx.Vb page please.

[b][red]This message was edited by DrMarten at 2006-11-23 11:18:36[/red][/b][hr]Hi I have the following code which runs fine under Visual Studio Pro 2005 on the localhost.[code]Partial Class _Default Inherits System.Web.UI.Page

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.

Comments

: [b][red]This message was edited by DrMarten at 2006-11-23 11:18:36[/red][/b][hr]: Hi I have the following code which runs fine under Visual Studio Pro 2005 on the localhost.: [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: : Dim Result As Integer: : Result = MsgBox("Hello", MsgBoxStyle.OkOnly): : End Sub: : End Class: [/code]: : When i try to run it on IIS server i get the following.>>: : Server Error in '/users/e5117204' 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 4: : Line 5: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click: Line 6: MsgBox("Hello!"): Line 7: End Sub: Line 8: End Class: : : Source File: E:FTPRootLocalUsere5117204VB-Basedsite1Default.aspx.vb Line: 6 : : 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) +1801778: 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.Button1_Click(Object sender, EventArgs e) in E:FTPRootLocalUsere5117204VB-Basedsite1Default.aspx.vb:6: 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.210 : : Any help would be much appreciated as i was hoping to do a web based game on an IIS account if this is possible?: : : : Regards,: : Dr M.: Hi, you can NOT show message box on ASP.NET page Imagine this situation:client is logged over putty to some unix-like server in text mode and runs some text web browser. Where is your message box supposed to appear?

Take a look into life cycle of webpage. Everything till Page_PreRender (and some later phrases on application level) occurs and runs ONLY on server side. Then, final page is rendered as HTML (or XHTML or anything you forced the page to return) and this HTML is send to client browser. Now, the page is interpreted.

If you want to force msgbox to appear, register startup script with javascript alert('your message'); inside.

Put some asp:label (let's say name="lblMsg") on your page and on button1_click set lblMsg.Text="your message"

After the message appears, take a look into final HTML code in your code. This is what client browser recieves.

ASP.NET has quite different life cycle than std winform..Clicking on that button does not mean that button.click is immediatelly processed. It causes Form.Submit and launches HTTP POST to your server. IIS recognise this and pass to your application. Now, new thread is created and new instance of _Default (or any other class) is created. (So, you've lost your class-level variables! For example), Page_Load occurs (and Page.IsPostBack is now TRUE), then occurs other page events and other events like button.click...and so on..

Don't forget that between 1st call to your page (type url into browser and get empty page) and clicking that button may pass serveral minutes, hours, days.. During one hour, there may exist completely different world of your application! Database has changed, somebody else could delete the record that your page is trying to modify, file you were viewing no longer exists or somebody else made changes to it and so on..

When you'll be watching page lifecycle, take a look into ViewState as well..

This part of the error message [b][blue]"Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.] "[/blue][/b] seems to indicate being able to set the defaultDesktopOnly?

Otherwise what is the point then of Microsoft making certain controls available in Visual Studio if you can't run the associated code in web design within Visual Studio for an aspx page?

If you wanted to do a web-site based game then, what scripting languages or other can you use please?Would this have to be on a standard server folder that is not an IIS account too please?

Do you know if all scripting languages can be mixed into one page or just certain ones please?

: Hi,: : This part of the error message [b][blue]"Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.] "[/blue][/b] seems to indicate being able to set the defaultDesktopOnly?

There's also this part:[blue]Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation.[/blue].

Do not forget, that your're building WEB application. It means, there's webbrowser sending HTTP POST or HTTP GET to your server, and you're generating response for this client (also on HTTP layer.)And this communication is PASSIVE! It means, client (resp. webbrowser) sends request and recieves your response (html page, mostly). And that's all you can. React to request. You cannot initiate communication, can not send anything after the response ends. (For example, send some message after 5 minutes timeout.)

Your application is running on server machine (not client's), and that is the computer you control.. If you need "reports", use database or file logs.. In old ASP application, when you use MsgBox, this message appeared on current server. Just imagine how many msgbox saw someone who connected to the server via remote desktop I would not like to click that OKs

: : Otherwise what is the point then of Microsoft making certain controls available in Visual Studio if you can't run the associated code in web design within Visual Studio for an aspx page?:

You just can not use WinForms-designed controls in web application, and you cannot use web-designed controls in WinForm application.Life cycle, context and method significantly differs..

In winforms, button has it's instance (with private variables etc) aviable during whole application run (until destroying it's container, of course ). In web page, button is created just for certain request (and is generated from aspx: ). It's created before Page.Load, and destroyed after Page.Prerender (or somewhen like that).. And it's rendered as .. No instance is provided to client, just html representation. Only one place, where button and other contols can persist it's state is ViewState (or ControlState in .NET 2.0), but this is rendered as hidden input type to http response, and decoded in next request..

: If you wanted to do a web-site based game then, what scripting languages or other can you use please?: Would this have to be on a standard server folder that is not an IIS account too please?:

You can use any client stripting language, but use Javascript for this.. (There's nothing better yet, unfortunatelly).But if you want to build game.. there's lot of techniques, how your game could be realised. If it's some kind of interactive game, you should use flash for example.. Because you will not be able to do this in aspx page.There's more possibilities, for example java applets, but I do NOT suggest you to use them If it's chess-like, adventure-like etc game, use postback technique of aspx page for this.. (clasic request-response..)

I'm afraid you'll need IIS on your server, because you have to create "Web Application".

: Do you know if all scripting languages can be mixed into one page or just certain ones please?:

You can use more scripting languages in one web page (javascript, vbscript).. As far as webbrowser can interpret them.. But you have to make separate block for them Just use javascript..