MessageBox.Show() for Asp.Net Web Forms

Joined
Jan 10, 2007
Messages
43,898
Location
In The Machine
[FONT=Verdana, Arial, Helvetica][FONT=Verdana, Arial, Helvetica] 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.

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

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

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

Youcould also write overloads for the static show() method to allow theclass to do a javascript confirm() or a prompt(). I haven't needed thatfunctionality yet so I've just kept it simple.
[/FONT][/FONT]

More...

View All Our Microsoft Related Feeds
 
Back
Top