Solved

message box in vb.net

Posted on 2004-10-10
5
7,755 Views
Last Modified: 2009-05-06
Hi all
I made an asp.net app and need message box to notify user for something.
IF user enter only one or none search criteria, message should looks like "You should enter more than one criteria!". I tried with MessageBox.Show, but I get an error "Name 'MessageBox' is not declared". When I tried with msgbox, I get an error "It is invalid to show a modal dialog or form when the application is not running in UserInteractive mode. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application." How can I use message box?

Thanks
0
Comment
Question by:dragy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
jnhorst earned 80 total points
ID: 12271817
MessageBox is for windows apps only.  The way to do this in ASP.NET is as follows:

Dim js As String = "<script language='javascript'>window.open('You should enter more than one criteria');</script>"
RegisterStartupScript("msgbox", js)

Put this code where you would otherwise have the MessageBox() call.  It will add this script block, which will cause a message box-like dialog to show from the browser.

John
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12271818
Oops, correction:

window.open('You should enter more than one criteria');

should be

alert('You should enter more than one criteria');

Sorry about that.

John
0
 
LVL 1

Author Comment

by:dragy
ID: 12272060
Thanks jnhorst,
One more thing, please. Can you explane me why messagebox.show or msgbox don't work on my app.
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12272745
In a Windows app, the base class for a form is System.Windows.Forms.  This is the namespace that has the MessageBox class that you use in VB.NET for Windows apps.  It in turn interacts with the Windows operating system to draw the message box with the message, icon and button you specify.  In a windows app, you always know you have a windows OS under the hood.

But with an ASP.NET app, the System.Web.UI namespace has a Page class that the web form inherits.  The Page class does not interact with the Windows OS to draw the box.  It's purpose is to configure HTML for IIS to send to the browser.  Where with VB.NET for windows you know your undelrying OS is going to be windows, with an ASP.NET app and a browser for the client, it may be on a unix box, a mac, or Linux, or who knows what.  So the only thing you know is that you will have a client capable of rendering HTML, and with some variations, capable of executing JavaScript.  And for security reasons, you also know the browser is not going to expose the underlying OS of the client's machine for you send the instructions ncessary to show a message box.

So if you want the browser to show a message box, you can be reasonable sure that the client's version of JavaScript will know how to respond to the alert() function.  But you have to tell the Page class to stream that function to the browser (RegisterStartupScript() is provided for just that purpose).  The way the browser knows you are sending it a JavaScript command is to have it embedded in the <script></script> tag as my initial response shows.

Remember two things:  1) Everything you put in an ASP.NET page that is an xml definition of a server control (like <asp:TextBox></asp:TextBox>), rather than regular HTML, is just a placeholder.  When a browser requests and aspx page, IIS has a runtime that receives that request.  When it sees <asp:TextBox...>, the runtime knows to instantiate the TextBox class of the System.Web.UI.WebControls namespace.  That class then tells the runtime what HTML to replace the <asp:Textbox...> tag with.  And 2) Think of the client browser as the OS.  With VB.NET for windows, windows is the OS and has various functionality to make interaction with the user possible.  With VB.NET "behind" and aspx page, it is the client browser that has that functionality.  If you want the user to put data in, then the TextBox class tells the runtime to send an <input type="text"...> tag.  If you want to show a message to the user, you either have to the JavaScript alert() function, or have a Label control that will send a <span...> tag with your message string.  Just think of the client browser as the "OS" of sorts.

John
0
 
LVL 1

Author Comment

by:dragy
ID: 12275288
Thank you John very much,
Now it's clearer than before, I see now what I should learn.

dragi
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

728 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