Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 2nd, 2003, 07:48 PM
Registered User
 
Join Date: Dec 2003
Location: Lubbock, Texas, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mnvijay Send a message via Yahoo to mnvijay
Default closing a form

hi guys,
  I am new to VS.NET. I am working with ASP.NET and C# to develop some web pages.
  Can anyone tell me how I can program the code so that whenever a user presses a button on the form the form will be closed.
  Also how do I show message box using C#. I am able to show message boxes when I program in console mode, but when i am doin a "ASP.NET Web application" i am not able to show up a dialog box.

waiting for ur help
thnks in advance.
-
vijay.

Naga Vijay Bhaskar Manchi
Reply With Quote
  #2 (permalink)  
Old December 3rd, 2003, 03:10 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

You can't use MessageBox.Show in a Web page. After all, the .NET Framework (which ASP.NET belongs to) runs at the server. Who would be there to click all those message boxes? ;)

If you want a message box, you'll need to send JavaScript to the client that calls the alert() method, so the messagebox will appear at the client. For example, this will work in an ASP / HTML / ASPX page:

<script language="JavaScript" type="text/javascript">
  alert('Hi, I am a Message Box');
</script>

How you use this in C# in ASPX pages depends on what you're trying to accomplish. You can add it to the ASPX page directly, or attach it to a control like a button or a link.

You can close a Web page with this code:

<script language="JavaScript" type="text/javascript">
  window.close();
</script>

Just as with the Message Box, you'll need to put this in your age somewhere, or add it to a button.

I suggest you get yourself a book or Web site about JavaScript if you want to learn things like this. ASP.NET is more that C# alone; you'll also need to know a thing or two about XHTML, CSS, JavaScript, etc.

HtH,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #3 (permalink)  
Old December 3rd, 2003, 06:21 AM
Registered User
 
Join Date: Dec 2003
Location: Lubbock, Texas, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mnvijay Send a message via Yahoo to mnvijay
Default

thank u very much...
-
vijay.

Naga Vijay Bhaskar Manchi
Reply With Quote
  #4 (permalink)  
Old June 25th, 2005, 01:52 AM
Authorized User
Points: 200, Level: 3
Points: 200, Level: 3 Points: 200, Level: 3 Points: 200, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2005
Location: , , Pakistan.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In html add <span id=msg runat="server">
in web.aspx.cs need to declare as protected system.Web.UI.HtmlControls.HtmlGenericControl msg;
in where you want disply message use this code
msg.InnerHtml = "<script>alert('just added your message'); window.location='frmUserAdd.aspx';</script>";
Reply With Quote
  #5 (permalink)  
Old December 18th, 2007, 07:20 AM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

i know this is an old thread but oh well...

if you want to use a messagebox add a new class called MessageBox and use the following code inside it


Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;

namespace Stuff
{
    /// <summary>
    /// Summary description for MessageBox.
    /// </summary>
    public class MessageBox
    {
        private static Hashtable m_executingPages = new Hashtable();

        private MessageBox(){}

        public static void Show( string sMessage )
        {
            // If this is the first time a page has called this method then
            if( !m_executingPages.Contains( HttpContext.Current.Handler ) )
            {
                // Attempt to cast HttpHandler as a Page.
                Page executingPage = HttpContext.Current.Handler as Page;

                if( executingPage != null )
                {
                    // Create a Queue to hold one or more messages.
                    Queue messageQueue = new Queue();

                    // Add our message to the Queue
                    messageQueue.Enqueue( sMessage );

                    // Add our message queue to the hash table. Use our page reference
                    // (IHttpHandler) as the key.
                    m_executingPages.Add( HttpContext.Current.Handler, messageQueue );

                    // Wire up Unload event so that we can inject 
                    // some JavaScript for the alerts.
                    executingPage.Unload += new EventHandler( ExecutingPage_Unload );
                }   
            }
            else
            {
                // If were here then the method has allready been 
                // called from the executing Page.
                // We have allready created a message queue and stored a
                // reference to it in our hastable. 
                Queue queue = (Queue) m_executingPages[ HttpContext.Current.Handler ];

                // Add our message to the Queue
                queue.Enqueue( sMessage );
            }
        }


        // Our page has finished rendering so lets output the
        // JavaScript to produce the alert's
        private static void ExecutingPage_Unload(object sender, EventArgs e)
        {
            // Get our message queue from the hashtable
            Queue queue = (Queue) m_executingPages[ HttpContext.Current.Handler ];

            if( queue != null )
            {
                StringBuilder sb = new StringBuilder();

                // How many messages have been registered?
                int iMsgCount = queue.Count;

                // Use StringBuilder to build up our client slide JavaScript.
                sb.Append( "<script language='javascript'>" );

                // Loop round registered messages
                string sMsg;
                while( iMsgCount-- > 0 )
                {
                    sMsg = (string) queue.Dequeue();
                    sMsg = sMsg.Replace( "\n", "\\n" );
                    sMsg = sMsg.Replace( "\"", "'" );
                    sb.Append( @"alert( """ + sMsg + @""" );" );
                }

                // Close our JS
                sb.Append( @"</script>" );

                // Were done, so remove our page reference from the hashtable
                m_executingPages.Remove( HttpContext.Current.Handler );

                // Write the JavaScript to the end of the response stream.
                HttpContext.Current.Response.Write( sb.ToString() );
            }
        }
    }
}
this can now be used from anwhere within your asp.net application by simply using MessageBox.Show("Hello i'm a message");

hope this helps someone at least



Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Form closing bschleusner C# 2005 2 February 4th, 2007 04:07 PM
How to refresh owner form on closing of child form akumarp2p C# 2005 0 December 22nd, 2006 10:27 AM
Closing a form after opening another form rosebushr Access 2 January 7th, 2006 04:34 AM
closing Form kobystud C# 4 July 1st, 2004 03:34 PM
Save Records Before Closing Form Ben Horne Access VBA 1 March 30th, 2004 11:47 PM



All times are GMT -4. The time now is 05:21 PM.


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