Click here to Skip to main content
15,860,972 members
Articles / Web Development / HTML
Article

Server Side MessageBox

Rate me:
Please Sign up or sign in to vote.
4.89/5 (36 votes)
19 Sep 20052 min read 217.8K   3.2K   106   52
A web (modal) messagebox without popup.

Sample Image

Sample Image

Introduction

As web developers, we always need model windows. But the simplest model window that comes from JavaScript has a problem: "Popup Blockers". You can write window.showModalDialog(...) in script, but what next?

My component, a web message box is a customizable modal dialog for ASP.NET 2.0, but not a popup and not a new window. It appears at the top of all objects and hides the others, so the other controls can not be clicked.

Background

The idea is very simple. In m control, I have some panels (<div>) and their z-indexes. I open a transparent panel at the top of all elements. So I prevent them being clicked. Then, I need a few new panels for the messagebox and some scripting and styling to show them.

The control has three events:

  • Btn1Clicked
  • Btn2Clicked
  • Btn3Clicked

Two styles:

  • msg.MessageBoxStyle.Violet
  • msg.MessageBoxStyle.Blue

And four icons:

  • msg.MessageBoxIcons.Exclamation
  • msg.MessageBoxIcons.Asteriks
  • msg.MessageBoxIcons.Question
  • msg.MessageBoxIcons.None

You can edit the visual affects by editing the InitializeIcon and InitializeStyle functions in Mbox.ascx.cs.

Using the control

Only thing you should do is add the Mbox.ascx user control and the Resources folder to your project. And then drag & drop the user control to your web form.

Image 3

Image 4

Add the following code to your default.aspx or whatever your file is..

C#
protected void Page_Load(object sender, EventArgs e)
{   //bind the events to messagebox buttons...
    Mbox1.Btn1Clicked += new EventHandler(Mbox1_Btn1Clicked);
    Mbox1.Btn2Clicked += new EventHandler(Mbox1_Btn2Clicked);
}
void Mbox1_Btn2Clicked(object sender, EventArgs e)
{
    Response.Write("2nd button clicked");
}

void Mbox1_Btn1Clicked(object sender, EventArgs e)
{
    Response.Write("1st button clicked");
}
C#
//Show methods and their overloads...
protected void Button1_Click(object sender, EventArgs e)
{
    Mbox1.Show("hede", "hodo");
}
protected void Button2_Click(object sender, EventArgs e)
{
    Mbox1.Show("My test message", "Warning", "OK", "Cancel", null);
}
protected void Button3_Click(object sender, EventArgs e)
{
    Mbox1.Show("My test message", "Warning", "OK", "Cancel", null, 
                                 msg.MessageBoxIcons.Exclamation);
}
protected void Button4_Click(object sender, EventArgs e)
{
    Mbox1.Show("My test message", "Warning", "OK", "Cancel", "Retry", 
               msg.MessageBoxIcons.Exclamation,msg.MessageBoxStyle.Violet);
}

I will not tell you more about this message box. I told you the logic behind it. A little effort will be enough to understand the code.

Points of Interest

The next version of the product will be a window-like popup control, but of course not a popup. It will be available soon... For bug reports and suggestions, I will wait for your mails at ozuolmez@msn.com.

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


Written By
Software Developer
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionMessage Box Pin
Milind Panchal19-Apr-12 3:15
Milind Panchal19-Apr-12 3:15 
SuggestionRe: Message Box Pin
BH TAN22-Dec-13 4:58
professionalBH TAN22-Dec-13 4:58 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey7-Feb-12 21:39
professionalManoj Kumar Choubey7-Feb-12 21:39 
QuestionCool Thanks :) Pin
pcsupport.ch30-Jul-11 9:02
pcsupport.ch30-Jul-11 9:02 
AnswerRe: Cool Thanks :) Pin
BH TAN22-Dec-13 4:58
professionalBH TAN22-Dec-13 4:58 
GeneralMy vote of 5 Pin
shoban_dotnet25-Feb-11 7:47
shoban_dotnet25-Feb-11 7:47 
Questiongrey out background??? Pin
simpa20-Apr-10 5:46
simpa20-Apr-10 5:46 
AnswerRe: grey out background??? Pin
simpa4-Mar-11 11:10
simpa4-Mar-11 11:10 
GeneralCool But.... Pin
sinister2318-Jan-10 22:56
sinister2318-Jan-10 22:56 
GeneralCool But.... Pin
sinister2318-Jan-10 22:56
sinister2318-Jan-10 22:56 
Generalwith Net 3.5 Pin
jtorresrios8-Sep-09 6:00
jtorresrios8-Sep-09 6:00 
GeneralDoesn't work in FireFox [modified] Pin
emanlee17-Jul-08 3:49
emanlee17-Jul-08 3:49 
GeneralRe: Doesn't work in FireFox Pin
chankl7827-Jul-08 20:40
chankl7827-Jul-08 20:40 
AnswerSolution: Doesn't work in FireFox Pin
BH TAN22-Dec-13 4:55
professionalBH TAN22-Dec-13 4:55 
Do refer http://forums.asp.net/t/1423396.aspx[^]to understand why Firefox shown Black

Solution: use css

You may modify below code from http://webdesignerwall.com/tutorials/cross-browser-css-gradient[^]

XML
<style type="text/css">
body {
    width: 600px;
    text-align: center;
    margin: 100px auto;
}
.gradient {
    width: 200px;
    height: 200px;

    background: #999; /* for non-css3 browsers */

    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#cccccc', endColorstr='#000000'); /* for IE */
    background: -webkit-gradient(linear, left top, left bottom, from(#ccc), to(#000)); /* for webkit browsers */
    background: -moz-linear-gradient(top,  #ccc,  #000); /* for firefox 3.6+ */
}

</style>
</head>

<body>
<div class="gradient">
    gradient box
</div>

GeneralTeşekkür... Pin
Member 353699911-Mar-08 5:04
Member 353699911-Mar-08 5:04 
Generalsession ends Pin
aapke_leeye27-Feb-08 0:18
aapke_leeye27-Feb-08 0:18 
GeneralDont´function Ajax (Atlas) Pin
psuporte4-Jul-07 6:26
psuporte4-Jul-07 6:26 
QuestionMoving the MessageBox [modified] Pin
ageltzer7-Jun-07 4:54
ageltzer7-Jun-07 4:54 
GeneralProblem with Master pages Pin
Pablopablo21-Aug-06 0:39
Pablopablo21-Aug-06 0:39 
GeneralRe: Problem with Master pages Pin
someone from the earth8-Dec-06 0:15
someone from the earth8-Dec-06 0:15 
QuestionDoes not work properly after publishing the WEB site Pin
Rohan Chandratileka9-May-06 19:59
Rohan Chandratileka9-May-06 19:59 
AnswerRe: Does not work properly after publishing the WEB site Pin
Britney S. Morales7-Sep-06 12:52
Britney S. Morales7-Sep-06 12:52 
Generalproblem in combination with user control Pin
hornox27-Apr-06 2:57
hornox27-Apr-06 2:57 
GeneralRun with Master page Pin
plumgrand20-Apr-06 14:48
plumgrand20-Apr-06 14:48 
GeneralRe: Run with Master page Pin
theboton29-May-06 3:02
theboton29-May-06 3:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.