Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

.NET MessageBox Control

0.00/5 (No votes)
11 Sep 2006 2  
For displaying Error,Warning or Information Messages in your ASP.NET WebSite

Sample Image - MessageBox.jpg

Introduction

.NET MessageBox Control Introduction This Control , as the name implies, is meant for Displaying messages in your Web Pages. Though it is a simple Web Control, I hope that this can be a good and simple introduction to Custom Controls.

How it is implemented?

The MessageBox is implemented by means of a Div Tag which is made draggable by means of a simple javaScript snippet. For this it is required to Override the Render Method of the WebControl . Inside the Render we are writing the MessageBox HTML. We have another Private method called SetClientScript which Outputs the required client script to the Page. Since the scripts are too long but so simple I am not gonna explain it here in detail.

How to Use the Control?

The Usage of this control is simple and neat. All you have to do is

  • compile your control project. 
  • open your website and right click anywhere in the toolbox and click choose items and browse for the Control DLL.
  • Your Control will get added to the ToolBox
  • Drop an instance of it to your page , set the Properties like Heading , Message etc and then set the Visible property to true. By default the Visible property is false .
  • The Images folder should contain error.gif,information.gif,warning.gif,close.gif Images.

From the Code Behind Page,

 this.MessageBox1.Message = �This is a Message�; 
 this.MessageBox1.MessageBoxMode = MessageBoxMode.Error; 
 this.MessageBox.Visible = true; 

Properties

Heading : Heading for the Message Box

Message :Message to be displayed

MessageBoxMode: The Type of the Message. The allowed values are, Information, Error, Warning

Color: The ForeColor

BackColor: The Background color for the Message Display Area.

HeadingForeColor: The Foreground color of the Heading Area

HeadingBackColor: The Background color of the Heading Area

AutoHide: A Boolean property indicating whether the MessageBox has to be autohided after a specific interval

AutoHideInterval: The interval for the AutoHide Property.

DropShadow: Boolean Property to specify whether to Drop a Shadow for the MessageBox.

ShadowColor: The color of the Shadow.

ShowButtons: Show the OK and MoreInfo Buttons.

IsModal: Specify whether the window is a modal window.

ImageFolder: Specify the Image Folder.

Position: By this Property , you can specify the position where the message box to be displayed.

Important

For the Appropriate behaviour of this control, The Document type of the Page should be
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

Conclusion

 I know that this is not a great control, but I feel that it may help some of you guys to get an idea over the Cusom Controls. Please do post your comments and I appreciate if you can provide any tips or suggestions to improve this control.

Cheers!!!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here