Wrox Programmer Forums
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 28th, 2005, 05:52 PM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default Messagebox

I've been trying to use messagebox. However, I've been unsuccessful. It keeps saying that MessageBoxButtons, DialogResult, and MessageBox are undefined. Here is my sample code:

If ServerName.Text.Length = 0 Then

            Dim Message As String = "You did not enter a server name. Cancel this operation?"
            Dim Caption As String = "No Server Name Specified"
            Dim Buttons As MessageBoxButtons = MessageBoxButtons.YesNo

            Dim Result As DialogResult

            Result = MessageBox.Show(Me, Message, Caption, Buttons)

            If Result = DialogResult.Yes Then

                Me.Close()

            End If

        End If

Can someone please tell me what I'm doing wrong or what I'm not doing? Thank you very much.

 
Old March 29th, 2005, 12:24 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Is this a web application? You can't use a Messagebox in a web application.

J
 
Old March 29th, 2005, 10:47 AM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, it is a web application. Is there something I can use then? Thanks.

 
Old March 29th, 2005, 01:05 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

The ways to put boxes on the screen with JScript are alert() and confirm().

When I have a web page that I sometimes want to have put up a 'message box,' I have added a function with a variable that I either do or do not fill, depending on whether I want the 'message box' to be shown or not.

Then I call that function when the page is loaded. I am using VB 6 and IIS, so values are filled in with replaceable tags that start with <WC_name_goes_here> and end with </WC_name_goes_here>.

This is what I have (in part):
Code:
   <script>

      var start_msg  = "<WC_OpeningMsg></WC_OpeningMsg>";


      function OpeningMessage()
        {
          if (start_msg != "") alert(start_msg);
        }

   </script>
   </head>

   <body onload="OpeningMessage();">
I’m not sure how, in .NET, you would fill in that variable, start_msg, but if you can do that, then here is one way to present a message box when showing a web page.

If you are trying to do all of this at the client, then you would just have client-side script that uses alert() to show a message.

In an allert() or in a confirm(), \n is a new line, quotes can be inserted with \".
Code:
    alert("Hello,\nhow are \"you\"?");
will produce:

    Hello,
    how are "you"?
 
Old March 29th, 2005, 01:11 PM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your help, Brian. But, I'm coding in VB and not Java. I really appreciate your help though.

Does anyone know how to produce a message using VB code in the .net enviornment? Thank you.

 
Old March 29th, 2005, 02:58 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

What Brian is trying to tell you to use is Javascript, not Java. This is one of the client side scripting languages used by web browsers.

To code something like this in VB.Net you can use the RegisterClientSideScript function to output a message to the client from within server side script.

Do a Google or search in the ASP.Net forums for this as I am sure I have seen examples of this many times (I may have even written one...)

Or you can simply add the Javascript to the HTML portion and manipulate it thru the client-side code.

J
 
Old March 29th, 2005, 04:20 PM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have done a search for RegisterClientSideScript, however, I have not come across any of that in these forums. I have even googled and didn't come up w/many matches. Can you please give me an example using this for alert()? Thanks.

 
Old March 29th, 2005, 04:40 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

alert() is a j[u]ava script</u> method. (So an example relating to alert() will—by definition—be a Java script answer.)

By putting javascript in the web page, you can cause the [u]browser</u> to present the popup.

Whatever solution you use, if you are building a web page (as opposed to a .NET framework application which uses the internet), the [u]browser</u> will have to do this for you. That, in turn, is accomplished with client-side script, either VB Script, or Java script. (Java script on the client is by far the most common way of adding script to a web page.)


Perhaps you noted in my initial post that I am using VB...

What—exactly—is it that you want to do?
    The user does - - -,
    then the visible result [u]to the user</u> is - - -,
    based on conditions like - - -?
 
Old March 29th, 2005, 05:00 PM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What I'm trying to do is create a message box when the delete button is pressed. What happens is that the user clicks on the delete button in which case brings up a message asking if they are sure they want to delete. I am currently using VB script in my aspx.vb file and I'm not sure how to incorporate Javascript in there. Can you please help me out? Thanks.

 
Old March 29th, 2005, 05:57 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Look here:

http://p2p.wrox.com/topic.asp?TOPIC_ID=11494

RegisterClientSideScript is similar to this, but this uses RegisterStartupScript. You can also look in the MSDN documentation for examples.

J





Similar Threads
Thread Thread Starter Forum Replies Last Post
MessageBox help Barkils C# 1 July 16th, 2007 09:30 PM
MessageBox Lalit Pradhan ASP.NET 2.0 Professional 1 July 5th, 2006 12:03 PM
MessageBox Ric_H General .NET 2 April 19th, 2006 01:45 PM
How to use MessageBox johnsonlim026 ASP.NET 1.0 and 1.1 Basics 7 June 17th, 2005 10:21 AM
MessageBox asbayani ASP.NET 1.0 and 1.1 Basics 3 July 29th, 2003 03:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.