Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 21st, 2008, 09:05 PM
Registered User
 
Join Date: Mar 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ScepterMT Send a message via Yahoo to ScepterMT
Default Creating a MessageBox in Asp.Net

When I began the programming for http://www.sceptermarkeingtechnologies.com, I quickly noticed that Asp.net does not support the MessageBox class that I was familiar with in windows forms.

Since Asp.net runs on the server it doesn't have access to produce a modal dialog box on the client. However, by using a scripting language that runs in the clients browser a similar construct is available. In javascript the window.alert() function will produce a modal dialog similar to what you would expect from MessageBox in windows forms.

So, I decided to create a static class MessageBox with a static method Show(), which will give you the ablility to to still use the syntax MessageBox.Show("Your Message"); and then convert it into the javascript window.alert("Your Message"); and add the script to the end of the current response stream.

I've written a how to on my blog at: http://sceptermt.blogspot.com/2008/0...lass-in-c.html that shows the source code that I used in C# for my web application and details on how it works.

You could also write overloads for the static show() method to allow the class to do a javascript confirm() or a prompt(). I haven't needed that functionality yet so I've just kept it simple.

Check This out: http://www.sceptermarketingtechnologies.com
 
Old March 22nd, 2008, 04:37 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

One comment about writing overloads for confirm or prompt is that this could be misleading from the perspective of the server code. The client side code runs only after the HTML is sent to to the browser. So any user response to a prompt or confirm dialog won't be seen at the server side but can only be consumed at the client side.

-Peter
peterlanoie.blog
 
Old March 23rd, 2008, 01:45 PM
Registered User
 
Join Date: Mar 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ScepterMT Send a message via Yahoo to ScepterMT
Default

You are right about the code being run on the client side and thus being the only forum for consuming the result from a confirm or prompt.

However, in an overloaded method javascript can be sent to the client that would cause the result of confirm or prompt to be posted back to the server where it can be handled on the server side.

It would be a quite complicated script but I was referring to the fact that it could be done.

Another approach to this problem is instead of using javascript you could use DHTML techniques to render the messagebox on the clients screen. That would allow the ok cancel or even yes no cancel buttons to be rendered as server controls as well as allowing the class to change the caption of the dialog or to style the whole thing to the design of your website.

Sorry if what I had said about overloading the send method being misleading, hope this post will clear things up.

Check This out: http://www.sceptermarketingtechnologies.com
 
Old March 24th, 2008, 01:01 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

No need to apologize. I've seen plenty of questions rooted in the misunderstanding of the separation of server-side and client-side code so I just wanted to clarify for the readers.

-Peter
peterlanoie.blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
display messagebox in ASP.Net with VB.Net suresh_accudocs ASP.NET 1.0 and 1.1 Basics 7 November 5th, 2014 06:31 PM
MessageBox en ASP.NET bloparod ASP.NET Espanol 4 September 24th, 2014 02:16 PM
Creating ContextMenu in Asp.net using c#? Hannibal ASP.NET 2.0 Basics 1 November 28th, 2006 04:07 PM
Creating an ASP.Net Application in VS.Net Maxood BOOK: Beginning ASP.NET 1.0 11 July 6th, 2004 03:09 PM
Creating ASP.NET Application in Visual Studio.NET Maxood ASP.NET 1.0 and 1.1 Basics 1 March 8th, 2004 01:56 PM





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