MessageBox in C# - errors

Z

Zeba

Hi guys,

I gave the following code in the page load function of one of my
codebehind pages :

if (!string.IsNullOrEmpty(keyword))
{
System.Windows.Forms.MessageBox.Show("Got your keyword!!");
SearchByKeyword();
}

I also included the reference for System.Windows.Forms, but I when I
try to view the page I get the error :

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.
What does this mean ?

Thanks!
 
K

khmer_lovers

you can't show messagebox in a web page. use Response.Write("bla bla");
instead.
 
Z

Zeba

So then in what context would you use

System.Windows.Forms.MessageBox.Show("sometext");

Thanks!
 
N

Nicholas Paldino [.NET/C# MVP]

Zeba,

Also, you don't have to write on the page if you don't want to. You can
insert text into the page which will call the Javascript function alert (on
the inherent window object exposed by the browser) in order to show a
messagebox on the client.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top